Let’s say we have some class structure:
public interface IA { public void doA(); }
public class A implements IA { public void doA(){ System.out.println("A class doA");}
public class B extends A { public void doA(){ System.out.println("B class doA"); }
And now in a main I state this:
//in a main
IA ia = new B();
ia.doA();
Am I correct in stating that the the runtime object of ia
is a B class and it has inherited all the super classes methods and attributes?
The printout from within the imaginary main is B class doA
as the method doA
in B will hide the same methods in its super classes?
5
Yes, you are correct.
ia
is of classB
-
ia
is also of classA
sinceB
inheritsA
. -
B
overrridesA
‘sdoA()
method.