-
Notifications
You must be signed in to change notification settings - Fork 1
/
Car02.java
58 lines (37 loc) · 964 Bytes
/
Car02.java
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
abstract class Vehicle {
private String brand;
public Vehicle(String brand) {
this.brand = brand;
}
public abstract void start();
public void displayBrand() {
System.out.println("Brand: " + brand);
}
}
class Car extends Vehicle {
// Constructor
public Car(String brand) {
super(brand);
}
@Override
public void start() {
System.out.println("Starting the car engine...");
}
}
class Bike extends Vehicle {
public Bike(String brand) {
super(brand);
}
@Override
public void start() {
System.out.println("Starting the bike engine...");
}
public static void main(String[] args) {
Car car = new Car("Toyota");
Bike bike = new Bike("Honda");
car.start();
bike.start();
car.displayBrand();
bike.displayBrand();
}
}