-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritDemo3.java
More file actions
51 lines (51 loc) · 1.03 KB
/
inheritDemo3.java
File metadata and controls
51 lines (51 loc) · 1.03 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
class inBox{
double width,height,depth;
inBox(inBox obj){
width = obj.width;
height = obj.height;
depth = obj.depth;
}
inBox(double w,double h,double d){
width = w;
height = h;
depth = d;
}
inBox(){
width = height = depth = -1;
}
inBox(double len){
width = height = depth = len;
}
double volume(){
return width*height*depth;
}
}
class BoxMass extends inBox{
double mass;
BoxMass(double w,double h,double d,double m){
width = w;
height = h;
depth = d;
mass = m;
}
}
class color extends inBox{
int color;
color(double w,double h,double d,int c){
super(w,h,d);
color = c;
}
}
public class inheritDemo3 {
public static void main(String args[]){
BoxMass obj1 = new BoxMass(3,4,6,1);
inBox obj2 = new inBox();
color obj3 = new color(4,2,5,7);
System.out.println(obj1.volume());
obj2 = obj1;
System.out.println(obj2.volume());
System.out.println(obj1.mass);
System.out.println(obj3.color);
// System.out.println(obj2.mass); //It is error because obj2 is inBox obj and it not contains mass
}
}