193k views
4 votes
A superclass must have a default, zero-parameter _______

a. Constructor
b. Destructor
c. Method
d. Variable

User Rochb
by
8.3k points

1 Answer

4 votes

Final answer:

A superclass in object-oriented programming must have a default, zero-parameter constructor. This is necessary for creating instances of the superclass or subclasses that do not explicitly call a superclass constructor with arguments.

Step-by-step explanation:

The question is asking about a requirement for a superclass in object-oriented programming. In such a context, a superclass must have a default, zero-parameter constructor. A constructor is a special method that is called when an object is instantiated. While it is not mandatory for a superclass to have a default constructor if subclasses provide all necessary parameters to super constructors, it becomes necessary when a subclass doesn't provide a constructor or when it needs to call a no-argument constructor of the superclass.

For example, in Java:

class SuperClass {
// Default, zero-parameter constructor
public SuperClass() {
// Constructor code here
}
}

class SubClass extends SuperClass {
public SubClass() {
super(); // Calls superclass's default constructor
}
}

It is important to note that if the superclass doesn't provide a default constructor and the subclass doesn't call another constructor explicitly, the code will not compile.

User Dongshengcn
by
8.3k points