- In Eclipse, create a new package in Java4Kids which is com.java4kids.car and a new Java class Car with the following methods:
public void start()
public void stop()
public int drive(int howlong)
The method drive has one argument – the driving time. The method has to return the total distance driven by the car for the specified time. Use the following formula to calculate the distance: distance = howlong*60;. Use the statement return distance as the last line in the method drive.
- Run this program in Eclipse.
- Write another class CarOwner with the method main that creates an instance of the object Car and call its methods. The result of each method call has to be printed using System.out.println().
- Create a subclass of Car named SuperCar and override the method drive Now use the following formula to calculate the distance: distance = howlong*180;
- Create an instance of the class SuperCar in the main method of CarOwner. Re-run the program CarOwner to see that it calls the overridden method drive.