-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBike.java
More file actions
40 lines (34 loc) · 1.15 KB
/
Bike.java
File metadata and controls
40 lines (34 loc) · 1.15 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
29
30
31
32
33
34
35
36
37
38
39
40
// Below application shows performing cloning bike pbjects instance
public class Bike implements Cloneable
{
private int engineNumber; // should be initialised by manufacturing company
private int modelNumber; //should be initialised by manufacturing company
private String type; //should be initialised by manufacturing company
private int bikeNumber; //should be initialised by RTO
public Bike(int engineNumber,int modelNumber,String type)
{
this.engineNumber = engineNumber;
this.modelNumber = modelNumber;
this.type = type;
}
public void setBikeNumber(int bikeNumber)
{
this.bikeNumber = bikeNumber; // RTO office calls this method to set bike number
}
//overriding clone method to develop aboive design
{
public Bike clone()throws CloneNotSupportedException
{
Bike newBike = (Bike)super.clone();
newBike.engineNumber = this.engineNumber + 10;
return newBike;
}
public String toString()
{
return "Bike Number:"+bikeNumber+"/n"+
"Engine Number:"+engineNumber+"/n"+ // TO print Object details
"Model Number:"+modelNumber+"/n"+
"Type :"+type;
}
}
}