Solved

What Is Printed? Public Class Inherit

Question 6

Multiple Choice

What is printed?

public class Inherit
{

class Figure
{
void display( )
{
System.out.println("Figure") ;
}
}

class Rectangle extends Figure
{
void display( )
{
System.out.println("Rectangle") ;
}
}

class Box extends Rectangle
{
void display( )
{
System.out.println("Box") ;
}
}

Inherit( )
{
Figure f = new Figure( ) ;
Rectangle r = new Rectangle( ) ;
Box b = new Box( ) ;
f.display( ) ;
f = r;
((Figure) f) .display( ) ;
f = (Figure) b;
f.display( ) ;
}

public static void main(String[ ] args)
{
new Inherit( ) ;
}
}


A) Figure
Rectangle
Box
B) Figure
Figure
Figure
C) Figure
Rectangle
Figure
D) Rectangle
Figure
E) none of the above

Correct Answer:

verifed

Verified

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

Related Questions