You are composing a simple Java program which includes two classes: Vehicle and Car. Car class is a derived class from the Vehicle class. You notice that when a Car object is created, it doesn't print out 'Vehicle constructor'. Fill the blanks in the code to make it so that the default constructor of the parent class is called when an object of the derived class is being created.
Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClass hierarchiesBuilding class hierarchies
Keyword "super"
Calling parent class constructor in derived class
Report a typo
Fill in the gaps with the relevant elements
class {
Vehicle() {
System.out.println("Vehicle constructor");
}
}
class Vehicle {
Car() {
();
System.out.println("Car constructor");
}
public static void main(String[] args) {
new Car();
}
} ___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.