Java OCA OCP Practice Question 2701

Question

Given:

2. class Animal {  
3.   void speak() { System.out.print("bark "); }  
4.   static void play() { System.out.print("catching "); }  
5. }  //from   w  ww. java2s .  c  om
6. class Main extends Animal {  
7.   void speak() { System.out.print("howl "); }  
8.   public static void main(String[] args) {  
9.     new Main().go();  
10.     super.play();  
11.     super.speak();  
12.   }  
13.   void go() {  
14.     super.play();  
15.     speak();  
16.     super.speak();  
17.   } 
18. } 

What is the result? (Choose all that apply.)

  • A. catching howl bark catching bark
  • B. catching howl howl catching howl
  • C. catching howl bark, then an exception.
  • D. Compilation fails due to an error on line 10.
  • E. Compilation fails due to an error on line 11.
  • F. Compilation fails due to an error on line 14.


D and E are correct.

Note

Remember "super" is an instance variable, so it CANNOT be used from the static context of main().




PreviousNext

Related