Oracle 1Z0-808 Exam question no. 6

Q.- Given the definitions of the Bird class and the Peacock class:-

public class Bird {
           public void fly( ) {
                      System.out.print ("Naman");
          }
}
public class Peacock extends Bird {
            public void dance ( ) {
                       System.out.print (" Tiwari.");
          }
}

and the code fragment:-

/*insert code snippet here */
p.fly ( );
p.dance ( );

Which code snippet can be inserted to print Naman Tiwari.

A) Bird p = new Peacock ( );

B) Peacock b = new Peacock ( );
     Bird p = (Bird) b;

C) Bird b = new Peacock( );
     Peacock p = (Peacock) b;

D) Bird b = new Bird ( );
     Peacock p = (Peacock) b;



⧪ please give your answer in a comment section.

Post a Comment

8 Comments