-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain4.java
More file actions
32 lines (30 loc) · 901 Bytes
/
Copy pathMain4.java
File metadata and controls
32 lines (30 loc) · 901 Bytes
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
29
30
31
32
class Vehicle {
public void start() {
System.out.println("Vehicle is starting.");
}
public void stop() {
System.out.println("Vehicle is stopping.");
}
}
class Car extends Vehicle {
public void openTrunk() {
System.out.println("Car trunk is opened.");
}
}
class SportsCar extends Car {
public void turboBoost() {
System.out.println("SportsCar turbo boost activated!");
}
}
public class Main4 {
public static void main(String[] args) {
// Create an object of SportsCar
SportsCar mySportsCar = new SportsCar();
// Call methods from all levels of the hierarchy
System.out.println("SportsCar Actions:");
mySportsCar.start(); // Method from Vehicle
mySportsCar.openTrunk(); // Method from Car
mySportsCar.turboBoost(); // Method from SportsCar
mySportsCar.stop(); // Method from Vehicle
}
}