Java OCA OCP Practice Question 3036

Question

Given:

3. class Shape {   
4.   void go1() { System.out.print("1 ");  }  
5.   final void go2() { System.out.print("2 "); }  
6.   private void go3() { System.out.print("3 "); }  
7. }  /*from   ww w.j  a va  2 s.co m*/
8. public class Main extends Shape {  
9.   void go1() { System.out.print("1b "); }  
10.   void go3() { System.out.print("3b "); }  
11.  
12.   public static void main(String[] args) {  
13.     new Main().go1();  
14.     new Shape().go1();  
15.     new Main().go2();  
16.     new Main().go3();  
17.     new Shape().go3();  
18. } } 

What is the result?

  • A. 1 1 2 3 3
  • B. 1b 1 2 3b 3
  • C. 1b 1b 2 3b 3b
  • D. Compilation fails due to a single error.
  • E. Compilation fails due to errors on more than one line.


D is correct.

Note

The only error is on line 17: Class Main cannot find class Shape's private go3() method.

Note that on line 10 we're NOT overriding class Shape's go3() method.




PreviousNext

Related