-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBike.java
More file actions
128 lines (100 loc) · 2.7 KB
/
Copy pathBike.java
File metadata and controls
128 lines (100 loc) · 2.7 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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package oops;
import java.io.Serializable;
public class Bike implements Serializable{
private String name;
private String model;
private String brand;
private int cc;
private double price;
public Bike() {
// TODO Auto-generated constructor stub
}
public Bike(String name) {
//constructor overloading
/*
* but every time we don't need to write this user defined instructions
* so we use one concept called constructor chaining
*
* we achieve constructor chaining in two ways
* 1.this()
* 2.super()
*
* but if we want to achieve constructor chaining inside same class we use this() call statements
* and we want achieve constructor chaining in two class we use super() call statement
*
* but we can't use this() call and super() inside same constructor at same time
*
* this() call or super() must be the first statement in constructor body
* and we use it inside only constructor body not a outside the constructor body*/
super();
this.name = name;
}
public Bike(String name, String model) {
//super();
this(name);
this.model = model;
}
public Bike(String name, String model, String brand) {
//super();
this(name, model);
this.brand = brand;
}
public Bike(String name, String model, String brand, int cc, double price) {
super();
this.name = name;
this.model = model;
this.brand = brand;
this.cc = cc;
this.price = price;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public int getCc() {
return cc;
}
public void setCc(int cc) {
this.cc = cc;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return "Bike [name=" + name + ", model=" + model + ", brand=" + brand + ", cc=" + cc + ", price=" + price + "]";
}
// @Override
// public boolean equals(Object obj) {
// Bike b=(Bike)obj;
// System.out.println("equals");
// return this.name==b.name&&this.model==b.model&&this.brand==b.brand&&this.cc==b.cc&&this.price==b.price;
// }
// @Override
// public int hashCode() {
//
// //System.out.println("hashcode()");
// return name.hashCode()+model.hashCode()+brand.hashCode()+cc+(int)price;
// }
// @Override
// public int compareTo(Bike o) {
// return o.price<this.price?1:o.price>this.price?-1:0;
// }
}