Java OCA OCP Practice Question 1846

Question

Consider the following class hierarchy

class A {/*from  www  .  j  a va  2  s . c  o  m*/
   public void m1 ()  {    }
}
class B extends A {
   public void m1 ()  {    }
}
class C extends B{
   public void m1 (){
      /*  //1
       ... lot of code.
      */
   }
}

Select 2 options

  • A. You cannot access class A's m1() from class C for the same object ( i.e. this).
  • B. You can access class B's m1() using super.m1() from class C.
  • C. You can access class A's m1() using ((A) this).m1() from class C.
  • D. You can access class A's m1() using super.super.m1() from class C.


Correct Options are  : A B

Note

Note that selection of method to be executed depends upon the actual object class.

So no matter what you do, in class C you can only access C's m1() even by casting this to B or A.

So, this option will not work.

There is no construct like super.super.

So, there is no way you can access m1() of A from C.




PreviousNext

Related