ProgrammingVery hardProduct-company placement · C++
How many of these are resolved at COMPILE time in C++? (i) Which function body a call to a non-virtual member function through a base-class pointer executes (ii) Which of several overloaded functions a call selects (iii) Which function body a call to a virtual function through a base-class reference executes (iv) Which instantiation of a function template a call uses
- A. 2
- B. 3
- C. 4
- D. 1
Correct answer: B. 3
(i), (ii) and (iv) are static (early binding): non-virtual calls use the static type, and overloads and template arguments are chosen by the compiler. Only (iii), virtual dispatch, depends on the run-time type.
More OOP with C++ and Java questions
- What is printed? java String b = "java"; String a = "ja" + "va"; String c = "ja"; String d = c + "va"; final String e = "ja"; String f = e…
- What is printed? java class A { void f(Object o) { System.out.print("AO "); } void f(String s) { System.out.print("AS "); } } class B…
- What is printed? java class P { String n = "P"; String get() { return n; } } class C extends P { String n = "C"; String get() { return n…
- What is printed? java class P { P() { show(); } void show() { System.out.print("P "); } } class C extends P { int x = 5; final int y = 7…
- What is printed? java static int f() { int x = 1; try { return x; } finally { x = 2; } } static StringBuilder g() { StringBuilder sb = new…
- What is printed? java static void m(StringBuilder a, StringBuilder b) { a.append("1"); b = a; b.append("2"); } // in main: StringBuilder x…