-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectCountDemo.java
More file actions
47 lines (39 loc) · 879 Bytes
/
ObjectCountDemo.java
File metadata and controls
47 lines (39 loc) · 879 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
class Box{
private double width,height,depth;
private static int count;
Box(){count++;}
Box(double w,double h,double d){
width = w;
height = h;
depth = d;
count++;
}
Box(double val){
width = height = depth = val;
count++;
}
Box(Box obj){
width = obj.width;
height = obj.height;
depth = obj.depth;
count++;
}
double volume() {
return width*height*depth;
}
static int getCount()
{
return count;
}
}
public class ObjectCountDemo {
public static void main(String[] args) {
System.out.println("No of objects created: "+Box.getCount());
Box myBox1 = new Box();
Box myBox2 = new Box(1,2,3);
System.out.println("No of objects created: "+Box.getCount());
Box myCube = new Box(5);
Box myClone = new Box(myBox2);
System.out.println("No of objects created: "+Box.getCount());
}
}