Java OCA OCP Practice Question 136

Question

Given:

3. class Dog { /*from   www.ja  v a 2 s.c  o  m*/
4.   public void bark() { System.out.print("woof "); } 
5. } 
6. class Hound extends Dog { 
7.   public void sniff() { System.out.print("sniff "); } 
8.   public void bark() { System.out.print("howl "); } 
9. } 
10. public class Main { 
11.   public static void main(String[] args) { new Main().go(); } 
12.   void go() { 
13.     new Hound().bark(); 
14.     ((Dog) new Hound()).bark(); 
15.     ((Dog) new Hound()).sniff(); 
16.   } 
17. } 

What is the result?

Choose all that apply.

  • A. howl howl sniff
  • B. howl woof sniff
  • C. howl howl followed by an exception
  • D. howl woof followed by an exception
  • E. Compilation fails with an error at line 14
  • F. Compilation fails with an error at line 15


F is correct.

Note

Class Dog doesn't have a sniff method.




PreviousNext

Related