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:

Verified
Correct Answer:
Verified
Q3: Which of the following classes would you
Q4: Write a set of code to define
Q5: Assume that x is a GUI component
Q6: What is printed?<br><br> public class Inherit<br> { <br><br> class Figure<br> {<br> void
Q7: A class reference can refer to any
Q9: Binary search can be used on unsorted
Q11: Considering the event processing classes, what is
Q12: One of the advantages of linear search
Q13: Write a set of code that will
Q36: It is possible to sort an array