Java OCA OCP Practice Question 104

Question

Given:

class Animal { /*from w  ww.ja  v a2  s.  c  o m*/
  private void fly() { 
     System.out.print("bang "); 
  } 
} 
public class Bird extends Animal { 
  public static void main(String[] args) { 
    new Bird().go(); 
  } 
  void go() { 
    fly(); 
    // Animal.fly();  // line A 
  } 
  private void fly() { System.out.print("sh-bang "); } 
} 

Which are true? (Choose all that apply.)

  • A. The output is bang
  • B. The output is sh-bang
  • C. Compilation fails.
  • D. If line A is uncommented, the output is bang bang
  • E. If line A is uncommented, the output is sh-bang bang
  • F. If line A is uncommented, compilation fails.


B and F are correct.

Note

Since Animal.fly() is private, it can't be overridden.

It is invisible to class Bird.

A, C, D, and E are incorrect based on the above.




PreviousNext

Related