What is printed by the following code? Consider the polymorphic invocation.
public class Inherit
{
class Figure
{
void display( )
{
System.out.println("Figure") ;
}
}
class Rectangle extends Figure
{
void display( )
{
System.out.println("Rectangle") ;
}
}
class Box extends Figure
{
void display( )
{
System.out.println("Box") ;
}
}
Inherit( )
{
Figure f = new Figure( ) ;
Rectangle r = new Rectangle( ) ;
Box b = new Box( ) ;
f.display( ) ;
f = r;
f.display( ) ;
f = b;
f.display( ) ;
}
public static void main(String[ ] args)
{
new Inherit( ) ;
}
}
A) Figure
Rectangle
Box
B) Rectangle
Box
C) Figure
Figure
Figure
D) Syntax error. This code won't compile or execute
E) none of the above
Correct Answer:
Verified
Q1: Which of the following GUI components would
Q2: What does the following code do? Assume
Q5: Assume that x is a GUI component
Q6: Comparing the performance of selection sort and
Q7: The showDialog method is part of which
Q8: What are the main programming mechanisms that
Q9: An int array stores the following values.
Q9: Which of the following GUI components would
Q10: Comparing the amount of memory required by
Q11: Which of the following is a listener
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