ProgrammingHardProduct-company placement · GATE CS
Classes A, B extends A and C extends B all override m(). Inside C, which way can call A's version of m() on the current object?
- A. super.super.m()
- B. ((A) this).m()
- C. A.super.m()
- D. None directly; C can only reach B's version through super.m()
Correct answer: D. None directly; C can only reach B's version through super.m()
Java has no super.super; ((A) this).m() still dispatches to C.m() and would recurse. A.super.m() is legal only for a directly implemented interface's default method. B must expose its own call to super.m() if C needs it.
More OOP with C++ and Java questions
- Joshua Bloch recommends implementing a singleton as a single-element enum. Which advantage does this give over a class with a private…
- What is printed? cpp struct P { const char s; P(const char s) : s(s) { cout << s; } ~P() { cout << "~" << s; } }; struct B { P b{"B"}; }…
- What is printed? cpp struct B { virtual ~B() { hi(); } virtual void hi() { cout << "B"; } }; struct D : B { ~D() { hi(); } void hi()…
- What is printed? cpp struct B { virtual void f(int x = 1) { cout << "B" << x; } }; struct D : B { void f(int x = 2) override { cout << "D"…
- What is printed? cpp struct B { void f(int) { cout << "Bi"; } void f(double) { cout << "Bd"; } }; struct D : B { void f(double) { cout <<…
- What is printed? cpp struct B { void f(int) { cout << "Bi"; } void f(double) { cout << "Bd"; } }; struct D : B { using B::f; void…