What is printed by this code?
public class Inherit
{
class Figure
{
void display( )
{
System.out.println("Figure") ;
}
}
class Rectangle extends Figure
{
void display( )
{
System.out.println("Rectangle") ;
}
void display(String s)
{
System.out.println(s) ;
}
}
class Box extends Figure
{
void display( )
{
System.out.println("Box") ;
}
void display(String s)
{
System.out.println("This is printed: " + s) ;
}
}
Inherit( )
{
Figure f = new Figure( ) ;
Rectangle r = new Rectangle( ) ;
Box b = new Box( ) ;
f.display( ) ;
f = r;
f.display("one") ;
f = b;
f.display("two") ;
}
public static void main(String[ ] args)
{
new Inherit( ) ;
}
}
A) Figure
Rectangle
B) Figure
Rectangle
Figure
Box
C) Figure
Figure
Figure
Figure
D) Rectangle
Figure
Box
Figure
E) Syntax error ,this code won't even compile
Correct Answer:
Verified
Q7: An int array stores the following values.
Q9: A polymorphic reference can refer to different
Q19: Which of the following GUI components would
Q21: What kind of performance can you expect
Q22: Can a program exhibit polymorphism if it
Q23: As explained in the Software Failure, the
Q25: A JSlider provides a list of String
Q26: Which of the following statements is completely
Q29: What is the efficiency of binary search?
A)
Q53: To swap the 3ʳᵈ and 4ᵗʰ elements
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents