Solved

What Is Printed by This Code

Question 24

Multiple Choice

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:

verifed

Verified

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

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents