-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
35 lines (35 loc) · 964 Bytes
/
Copy pathRectangle.java
File metadata and controls
35 lines (35 loc) · 964 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
//CONSTRUCTOR
//class declaration
public class Rectangle {
//non-static members
public int length;
public int breadth;
public int height;
//create constructor
public Rectangle(int length, int breadth) {
this.length = length;
this.breadth = breadth;
}
//create another constructor
public Rectangle(int length, int breadth, int height) {
// this(length, breadth);
this(length, breadth);
this.height = height;
}
//create a method
public void areaof2drect() {
int area = length*breadth;
System.out.println(area);
}
//create another method
public void areaof3drect() {
int area = length*breadth*height;
System.out.println(area);
}
public static void main(String[] args) {
Rectangle p1 = new Rectangle(10, 20);
p1.areaof2drect();
Rectangle p2 = new Rectangle(10, 20, 30);
p2.areaof3drect();
}
}