✏️ Explanatory Question

[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);
    }
}

  

👁 28 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

Answer not available right now.