-
Notifications
You must be signed in to change notification settings - Fork 0
/
overriding1.java
45 lines (44 loc) · 972 Bytes
/
overriding1.java
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
class figure{
double dim1;
double dim2;
figure(double a,double b){
dim1=a;
dim2=b;
}
double area(){
System.out.println("area for figure is undefined");
return 0;
}
}
class rectangle extends figure{
rectangle(double a,double b){
super(a,b);
}
double area(){
System.out.println("inside area for rectangle");
return dim1*dim2;
}
}
class triangle extends figure{
triangle(double a,double b){
super(a,b);
}
double area(){
System.out.println("inside area for triangle");
return dim1*dim2/2;
}
}
class findareas{
public static void main(String a[]){
figure f=new figure(10,10);
rectangle r=new rectangle(9,5);
triangle t=new triangle(10,8);
figure figuref;
figuref=r;
System.out.println("area is "+figuref.area());
figuref=t;
System.out.println("area is "+figuref.area());
figuref=f;
System.out.println("area is "+figuref.area());
}
}