Given a scenario where there is a superclass named Vehicle which has a constructor and a getter method, and a subclass named Car. You need to utilize inheritance mechanism to execute the functionality of subclass Car. When you create an instance of Car, the system should print 'Car'. Fill the blanks in the provided Java code to achieve this.
Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClass hierarchiesBuilding class hierarchies
Inheritance
Using inheritance to print car instance
Report a typo
Fill in the gaps with the relevant elements
class Vehicle {
String type;
public Vehicle (String type) {
this.type = type;
}
public String getType() {
return type;
}
}
public class Car Vehicle {
public Car(){
("Car");
}
}
public class Main {
public static void main(String[] args) {
Car myCar = new Car();
System.out.println(myCar.getType());
}
} ___
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.