Inheritance in Object-Oriented Programming
In Java, what happens when a subclass constructor does not explicitly call a superclass constructor?
The variables from the superclass are not initialized.
The subclass fails to compile until a call to the superclass’s constructor is added.
An exception is thrown at runtime due to incomplete object construction.
The default no-argument superclass constructor is called automatically.
How can you confirm that your subclass's overridden method behaves as expected?
By creating test cases comparing its output with known results.
By making all methods abstract in the parent class.
By using only default constructors in both classes during testing
By deleting other methods in the subclass temporarily.
If a superclass's constructor takes in four parameters, how many parameters should the subclass's constructor have?
There is no requirement and depends on the subclass one wants to write.
Zero parameters.
Four parameters.
Two parameters.
Which statement accurately describes how to override an inherited method within a subclass?
Declare a new method with only a matching name but different parameters
Use super.methodName() within the new method to indicate an override
Change the method’s return type to differentiate it from that of its superclass
Provide a method with the same signature and return type as in its superclass
How can a subclass constructor make sure that initialization happens correctly while also allowing for additional settings specific to that subclass?
Use super()
with arguments followed by subclass-specific initializations.
Assume that all initialization is done automatically without needing super()
.
Arrange for the superclass constructor to call subclass constructors.
Rely solely on default constructors without parameters or separate initializations.
When using the "super" keyword to call a superclass's constructor, what parameters should be passed?
Parameters required by the subclass constructor's signature.
Parameters required by the superclass constructor's signature followed by parameters required by the subclass constructor's signature.
No parameters should ever be passed when using "super".
Parameters required by the superclass constructor's signature.
What keyword is used in Java to call a superclass's constructor within a subclass's constructor?
class
extends
super
this

How are we doing?
Give us your feedback and let us know how we can improve
What must be included when defining an explicit value-setting (parameterized) constructor on an "Animal" Class?
Obtain inputs through parameters
Leave out an explicit method declaration
Do not include data types
Add parameters outside parentheses
When defining a subclass in Java, which keyword indicates that it is inheriting properties from another class?
implements
super
extends
private
Consider the following superclass and subclass declarations:
java
public class Shape {
private String color;
public Shape(String color) {
this.color = color;
}
public String getColor() {
return color;
}
}
public class Circle extends Shape {
private double rad...
super(radius); this.radius = radius;
super(color); this.radius = radius;
this(color); this.radius = color;
super(radius); this.color = color;