Java OCA OCP Practice Question 2961

Question

Given:

5. class Shape { void doShape() { System.out.print("oo "); } }  
6. class Rectangle extends Shape {  
7.   void doShape() { System.out.print("gui "); }    
8. }  // w w  w .  j  ava 2  s  . c om
9. public class Main extends Rectangle {  
10.   void doShape() { System.out.print("button "); }  
11.   public static void main(String[] args) { new Main().go(); }  
12.   void go() {  
13.     Rectangle g = new Rectangle();  
14.     // this.doShape();   
15.     // super.doShape();   
16.     // g.super.doShape();   
17.     // super.g.doShape();   
18.     // super.super.doShape();   
19. } } 

If the commented lines are uncommented independently, which are true? (Choose all that apply.)

  • A. If line 14 is uncommented, "button" will be in the output.
  • B. If line 15 is uncommented, "gui" will be in the output.
  • C. If line 16 is uncommented, "oo" will be in the output.
  • D. If line 17 is uncommented, "oo" will be in the output.
  • E. If line 18 is uncommented, "oo" will be in the output.


A and B use the correct syntax.

Note

C, D, and E are incorrect because none of them allow you to invoke OOThing.doShape() from the Main class.




PreviousNext

Related