Convert vehicles and cars to string

Report a typo

There are two classes Vehicle and Car. The second class extends the first one.

Override toString in both classes to return a string representation of vehicles and cars.

If an object is Vehicle, the overridden method toString must return something like:

Vehicle{licensePlate=ABC123}

If an object is Car, the overridden method toString must return something like:

Car{licensePlate=ABC123,numberOfSeats=4}
Write a program in Java 17
class Vehicle {

protected String licensePlate;

public Vehicle(String licensePlate) {
this.licensePlate = licensePlate;
}
}

class Car extends Vehicle {

protected int numberOfSeats;

public Car(String licensePlate, int numberOfSeats) {
super(licensePlate);
this.numberOfSeats = numberOfSeats;
}
}
___

Create a free account to access the full topic