Java OCA OCP Practice Question 407

Question

Which of the given statements are correct about the following code?

//Filename: Main.java 
class Main{ // w ww  . j  av a2 s.co  m
   public static void main (String [] args){ 
      A a = new A (); 
      B b = new B (); 
    }; 
} 
class A implements T1, T2{} 
class B extends A implements T1{} 
interface T1  {  } 
interface T2  {  } 

Select 4 options

  • A. (a instanceof T1) will return true.
  • B. (a instanceof T2) will return true.
  • C. (b instanceof T1) will return true.
  • D. (b instanceof T2) will return true.
  • E. (b instanceof A) will return false.


Correct Options are  : A B C D

Note

It will return true because B extends A and 'b' is referring to an object of class B.

Since A implements both T1 and T2, 1 and 2 are correct.

b instanceof A will return true as B is a subclass of A. Note that it is 'A' and not 'a'.

( b instanceof a ) will not compile.




PreviousNext

Related