-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
28 lines (26 loc) · 1.14 KB
/
Copy pathMain.java
File metadata and controls
28 lines (26 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Main {
public static void main(String[] args) {
// Regular Bike
System.out.println("=== Bike Details ===");
Vehicle bike = new Bike("Yamaha", "R15", 180000, false);
bike.displayInfo();
bike.start();
bike.stop();
System.out.println("\n=== Electric Car Details ===");
// Electric Car (Multiple Inheritance: Vehicle + ElectricVehicle + SmartFeatures)
ElectricCar tesla = new ElectricCar("Tesla", "Model 3", 4800000, 75);
tesla.displayInfo();
tesla.start();
tesla.chargeBattery();
// FIX: Call the default method using a cast to the interface type
((ElectricVehicle) tesla).displayChargingInfo();
tesla.enableAutoDrive();
tesla.connectToApp();
tesla.stop();
// Polymorphism using Interface Reference
System.out.println("\n=== Interface Polymorphism ===");
ElectricVehicle evRef = tesla; // Reference via interface
evRef.chargeBattery(); // Access only ElectricVehicle methods
System.out.println("Battery Level via Interface: " + evRef.getBatteryLevel() + "%");
}
}