Java question on car classes task (polymorphism)
Hi, I think there is a bug in this assignment. Below is the full code I implemented which returns completely nothing. Even when I erase ElectricVehicle and HybridVehicle classes to just output vehicle.start() and .resource() which has been given in the assignment, nothing happens. Could you help me on this? class Main { public static void main(String[] args) { Vehicle vehicle = new Vehicle(); Vehicle electric = new ElectricVehicle(); Vehicle hybrid = new HybridVehicle(); //calls vehicle.start(); vehicle.resource(); electric.start(); electric.resource(); hybrid.start(); hybrid.resource(); } } class Vehicle{ public void start(){ System.out.println("Starting"); } public void resource(){ System.out.println("I use petrol"); } } class ElectricVehicle extends Vehicle{ /*reimplement resource() method to output "I use electricity"*/ public void resource(){ System.out.println("I use electricity"); } } } class HybridVehicle extends Vehicle{ /*reimplement resource() method to output "I use both petrol and electricity"*/ public void resource(){ System.out.println("I use petrol and electricity"); } }