Inheritance in Object-Oriented Programming
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.
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.
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.
What keyword is used in Java to call a superclass's constructor within a subclass's constructor?
class
extends
super
this
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

How are we doing?
Give us your feedback and let us know how we can improve
When designing a subtype constructor which should ensure a certain invariant condition maintained across all instances, what approach should be taken?
Add assertion statements at the end of both super and subclass constructors testing post-conditions prior to object release.
Include invariant check in separate public method called immediately after object creation on client side instead.
Assert condition using static block initially during class loading phase ensuring setup before any construction happens.
Invoke method enforcing invariant within this very constructor after calling superclass constructor but before completing current one.
Inheriting from a class Vehicle, what would make Car subclass invalid?
Vehicle being final or concrete enough so no further inheritance can take place
Car lacking default constructor though Vehicle provides one.
Vehicle having conflicting non-final static fields shared among different classes.
Vehicle having too many methods making complexity high preventing easy inheritance.
If a subclass needs to throw an exception during the construction process due to invalid parameters, where should this validation code be placed?
Inside the subclass's constructor before calling the superclass constructor with valid parameters.
Before instantiation of any objects from either superclass or subclass within client code.
Inside a separate method called by the superclass constructor after initialization.
After initializing all properties in both superclass and subclass constructors.