-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.java
More file actions
32 lines (25 loc) · 786 Bytes
/
3.java
File metadata and controls
32 lines (25 loc) · 786 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
class Rectangle {
int length, breadth;
Rectangle() {
this.length = 0;
this.breadth = 0;
}
Rectangle(int length, int breadth) {
this.length = length;
this.breadth = breadth;
}
Rectangle(int side) {
this.length = this.breadth = side;
}
public int calculateArea() {
return length * breadth;
}
public static void main(String[] args) {
Rectangle r1 = new Rectangle();
Rectangle r2 = new Rectangle(5, 10);
Rectangle r3 = new Rectangle(7);
System.out.println("Area (no parameters): " + r1.calculateArea());
System.out.println("Area (two parameters): " + r2.calculateArea());
System.out.println("Area (one parameter): " + r3.calculateArea());
}
}