-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathCar.java
66 lines (48 loc) · 1.39 KB
/
Car.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
61
62
63
64
65
66
/**
* This program demonstrate Abstract Class.
* @version 1.01- 17-08-2018
* @author Abhey Rana
*/
import java.util.Calendar;
import java.util.Date;
public abstract class Car{
// Abstract Class can also have instance variables .....
private String modelName;
private int passengerCapacity;
private double topSpeed;
private Date manufacturingDate;
// Abstract Class can have constructor just like other classes ....
public Car(String modelName, int passengerCapacity, double topSpeed){
this.modelName = modelName;
this.passengerCapacity = passengerCapacity;
this.topSpeed = topSpeed;
this.manufacturingDate = Calendar.getInstance().getTime();
}
// Abstract Methods
public abstract void accelerate();
public abstract void brake();
public abstract String getDescription();
// Accessor Methods (See Abstract Class can also have concrete methods)
public String getModelName(){
return this.modelName;
}
public int getPassengerCapacity(){
return this.passengerCapacity;
}
public double getTopSpeed(){
return this.topSpeed;
}
public Date getManufacturingDate(){
return this.manufacturingDate;
}
// Mutator Methods
public void setModelName(String modelName){
this.modelName = modelName;
}
public void setPassengerCapcity(int passengerCapacity){
this.passengerCapacity = passengerCapacity;
}
public void setTopSpeed(double topSpeed){
this.topSpeed = topSpeed;
}
}