57.0k views
4 votes
Suppose you create a class Square to be a subclass of GeometricObject. Analyze the following code:

class Square extends GeometricObject {
double length;

Square(double length) {
GeometricObject(length);
}
}
A. The program compiles fine, but you cannot create an instance of Square because the constructor does not specify the length of the Square.
B. The program has a compile error because you attempted to invoke the GeometricObject class's constructor illegally.
C. The program compiles fine, but it has a runtime error because of invoking the Square class's constructor illegally.

1 Answer

4 votes

Answer:

B. The program has a compile error because you attempted to invoke the GeometricObject class's constructor illegally.

Step-by-step explanation:

To call a superclass constructor, the user must use super(). This is necessary unless default constructors are used. Also, it is vital to make sure if their are appropriate argument to be used while invoking the superclass constructor.

User Temi Fakunle
by
6.7k points