-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy path21_ClassObjects.java
More file actions
60 lines (43 loc) · 924 Bytes
/
21_ClassObjects.java
File metadata and controls
60 lines (43 loc) · 924 Bytes
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, Objects, Instance and Field Variable
* */
public class Main {
public static void main(String[] args) {
Rectangle r1 = new Rectangle();
r1.setLength(10);
r1.setBreadth(20);
Rectangle r2 = r1;
r2.setLength(50);
r2.setBreadth(100);
Rectangle r3 = new Rectangle();
Rectangle r4 = new Rectangle();
Rectangle r5 = new Rectangle();
System.out.println(r1.getBreadth());
System.out.println(r1.getLength());
}
}
public class Rectangle {
int length; // or it can be float
int breadth;
public float getArea() {
float area = length * breadth;
return area;
}
public float findPerimeter() {
int p = 2 * ( length + breadth );
return p;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getBreadth() {
return breadth;
}
public void setBreadth(int breadth) {
this.breadth = breadth;
}
}