If a superclass A has a method foo and a derived class B has

If a superclass A has a method foo() and a derived class B has a method foo(), which method is called by the following code:

B b = new B();
A a = b;
a.foo();

The foo() method in class B.

Solution

Answer: The foo() method in class B.

We created instance of B and assinged it to parent class instance.

Though we are calling foo() method by superclass object, derived class foo() method will invoke.

If a superclass A has a method foo() and a derived class B has a method foo(), which method is called by the following code: B b = new B(); A a = b; a.foo(); Th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site