Question
Result 1961
[Inheritance] Study the given two classes below and identify the error, if any, in the given code. class Vehicle { protected String colour; protected String registration; public Vehicle(String c, String r) { colour = c; registration = r; } public void show() { System.out.println("Colour: " + colour); System.out.println("Registration number: " + registration); } } class Car extends Vehicle { private double weight; private String model; public Car(String model, double weight, String colour, String registration) { this.model = model; this.weight = weight; super(colour, registration); } public void show() { super.show(); System.out.println("Car Model name = " + model); System.out.println("Car body weight = " + weight); } }
Error: The statement super(colour, registration); must be the FIRST statement inside the constructor. Understanding the Problem: The class Car inherits the class Vehicle. Therefore, the constructor of the parent class (Vehicle) is called using: super(colour, r...
View Details
/question/11118