ProgrammingHardProduct-company MCQ pattern
Which C++ operator can be overloaded only as a non-static member function, never as a free function?
- A. ==
- B. +
- C. <<
- D. = (assignment)
Correct answer: D. = (assignment)
Assignment =, subscript [], call () and member access -> must be members. +, << and == are often written as free (friend) functions so that the left operand need not be the class type.
More OOP with C++ and Java questions
- What is printed? java List<Integer> l = Arrays.asList(1, 2, 3); try { l.set(0, 9); System.out.print(l); l.add(4); } catch…
- What is printed? java Map<String, Integer> m = new HashMap<>(); System.out.print(m.put("a", 1)); System.out.print(" " + m.put("a", 2))…
- What does sizeof print for an empty class in C++? cpp class Empty { }; int main() { cout << sizeof(Empty); }
- What is printed? java System.out.print("apple".compareTo("apricot") + " " + "app".compareTo("apple") + " " + "b".compareTo("a"));
- What is printed? java class P { static void sm() { System.out.print("P"); } void im() { System.out.print("P"); } } class C extends P {…
- What is printed? java class P { int x = 10; int getX() { return x; } } class C extends P { int x = 20; int getX() { return x; } } // in…