Solved

What Is Printed by the Following Code? Consider the Polymorphic

Question 8

Multiple Choice

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:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions