ProgrammingHardGATE CS · TCS NQT Prime · Product Company SDE
Which kind of call in C++ is resolved using static (compile-time) binding rather than dynamic (run-time) binding?
- A. A call to a virtual function through a base-class pointer
- B. A call to a virtual function through a base-class reference
- C. A call to a non-virtual member function
- D. A call to an overridden virtual function through any pointer or reference to the base
Correct answer: C. A call to a non-virtual member function
Only virtual function calls use the vtable for dynamic dispatch; non-virtual member function calls are always resolved at compile time based on the static type of the expression.
More OOP with C++ and Java questions
- Which of these can a Java interface still NOT have, even in a modern version such as Java 17?
- A class overrides equals() but does not override hashCode(). What bug does this risk for instances used as keys in a HashMap or stored in…
- Which run-time mechanism lets a call through a base-class pointer invoke the correct derived-class override in C++?
- cpp struct A { void f() { cout << "A::f"; } }; struct B : A {}; struct C : A {}; struct D : B, C {}; int main() { D d; d.f(); } What…
- Why can a private method in a Java superclass never be overridden by a subclass, only unintentionally hidden (i.e. always statically bound)?
- cpp struct A { int x = 1; }; struct B : A {}; struct C : A {}; struct D : B, C {}; int main() { D d; // d.x ? } Without virtual…