0

Why is this code not working

class Main { public static void main(String[] args) { Vehicle vehicle = new Vehicle(); Vehicle electric = new ElVehicle(); 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 ElVehicle 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 both petrol and electricity"); }

20th Jun 2023, 10:17 AM
Moses Solomon Ayofemi
Moses Solomon Ayofemi - avatar
3 Answers
+ 3
People more readily test your code when you LINK it instead of pasting it into the description box.
20th Jun 2023, 10:27 AM
Lisa
Lisa - avatar
+ 3
Follow the steps to share your code as a link: https://code.sololearn.com/Wek0V1MyIR2r/?ref=app
20th Jun 2023, 10:41 AM
Hasnain [ACTIVE CHALLENGER]
Hasnain [ACTIVE CHALLENGER] - avatar
0
You forgot to put } closing braces at the end of resource() method in ElVehicle and HybridVehicle class. Make sure that all your braces are in pairs!
20th Jun 2023, 12:16 PM
Tibor Santa
Tibor Santa - avatar