ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
// static methods of the main class:
static void f(int... a) { System.out.print("V"); }
static void f(int a, int b) { System.out.print("F"); }
// in main:
f(1, 2);
f(1, 2, 3);- A. Compilation error: ambiguous call
- B. FV
- C. VV
- D. FF
Correct answer: B. FV
Overload resolution tries methods without varargs first, so f(1, 2) matches f(int, int) exactly: F. Only f(int...) can take three arguments: V.
More OOP with C++ and Java questions
- Which member function fails to compile? cpp class C { int a = 0; mutable int hits = 0; public: int get() const { hits++; return a; } void…
- Which C++ operator can be overloaded only as a non-static member function, never as a free function?
- 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"));