Calling a Superclass Constructor
Consider the following class definitions.
public class Rectangle
{
private int height;
private int width;
public Rectangle()
{
height = 1;
width = 1;
}
public Rectangle(int x)
{
height = x;
width = x;
}
public Rectangle(int h, int w)
{
height = h;
width = w;
}
// There may be methods that are not shown.
}
public class Square extends Rectangle
{
public Square(int x)
{
/* missing code */
}
}
Which code segment can replace /* missing code */ in the Square constructor to initialize the inherited instance variables height and width to the value of x?
A
Rectangle(x);
B
height = x; width = x;
C
super(x);
D
super();
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE