- 1

Hi guys whats wrong with this code?

class Main { public static void main(String[] args) { Scanner myVar = Scanner (System.in); 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{ public void start(){ System.out.println("Starting"); } public void resource(){ System.out.println("I use electricity"); /*reimplement resource() method to output "I use electricity"*/ } class HybridVehicle extends Vehicle{ public void start(){ System.out.println("Starting"); } public void resource(){

3rd Jan 2022, 3:28 PM
Narges Abbasi
3 odpowiedzi
+ 1
// NEW Scanner myVar = new Scanner(System.in);
3rd Jan 2022, 3:46 PM
SoloProg
SoloProg - avatar
+ 1
class Main { public static void main(String[] args) { Vehicle vehicle = new Vehicle(); Vehicle elVehicle = new elVehicle(); Vehicle hybrid = new HybridVehicle(); //calls vehicle.start(); vehicle.resource(); elVehicle.start(); elVehicle.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"); } }
10th Jul 2022, 7:20 AM
Hafizh Maalik Falah
0
Thanks
3rd Jan 2022, 4:08 PM
Narges Abbasi