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:

Verified
Correct Answer:
Verified
Q11: Java allows one to create polymorphic references
Q16: Explain why an abstract method cannot be
Q17: Write a set of code that will
Q18: The showDialog method is part of which
Q19: Which of the following GUI components would
Q20: Regarding the Software Failure: There was a
Q22: Which statement is completely True?<br>A) Java upcasts
Q23: Consider the code shown below. It contains
Q26: What is printed? <br><br> public class Inherit<br> {<br><br> abstract class
Q46: An int array stores the following values.