Java OCA OCP Practice Question 2449

Question

Given:.

2. class MyClass { }  
3. public class Shape extends MyClass {  
4.   public static void main(String[] args) {  
5.     MyClass ff = new MyClass();  
6.     Shape b = new Shape();  
7.     // insert code here  
8.   }  
9. } 

Which, inserted independently at line 7, compile? (Choose all that apply.)

  • A. if(b instanceof ff) System.out.print("1 ");
  • B. if(b.instanceof(ff)) System.out.print("2 ");
  • C. if(b instanceof MyClass) System.out.print("3 ");
  • D. if(b instanceOf MyClass) System.out.print("4 ");
  • E. if(b.instanceof(MyClass)) System.out.print("5 ");


C is the correct syntax.



PreviousNext

Related