-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVehicle91.java
60 lines (53 loc) · 1.19 KB
/
Vehicle91.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
59
60
class Vehicle
{
private String make;
private String model;
public Vehicle(String make, String model)
{
this.make = make;
this.model = model;
}
public void displayInfo()
{
System.out.println("Make: " + make);
System.out.println("Model: " + model);
}
}
class Car extends Vehicle
{
private int numDoors;
public Car(String make, String model, int numDoors)
{
super(make, model);
this.numDoors = numDoors;
}
public void displayInfo()
{
super.displayInfo();
System.out.println("Number of Doors: " + numDoors);
}
}
class Motorcycle extends Vehicle
{
private int engineSize;
public Motorcycle(String make, String model, int engineSize)
{
super(make, model);
this.engineSize = engineSize;
}
public void displayInfo()
{
super.displayInfo();
System.out.println("Engine Size: " + engineSize + " cc");
}
}
public class Vehicle91
{
public static void main(String[] args) {
Car car = new Car("Honda", "Civic", 4);
Motorcycle motorcycle = new Motorcycle("Yamaha", "R6", 600);
car.displayInfo();
System.out.println();
motorcycle.displayInfo();
}
}