-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path40.java
More file actions
44 lines (40 loc) · 842 Bytes
/
40.java
File metadata and controls
44 lines (40 loc) · 842 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
interface figure
{
double half = 0.5;
double pie = 3.14;
double area (double x, double y);
}
class rectangle implements figure
{
public double area(double l, double b)
{
return l*b;
}
}
class triangle implements figure
{
public double area(double b, double al)
{
return half*b*al;
}
}
class circle implements figure
{
public double area(double r, double y)
{
return pie*r*r;
}
}
class figdemo
{
public static void main(String[] args)
{
figure figref;
figref = new rectangle();
System.out.println("Area of rectangle: " + figref.area(2.0,3.0));
figref = new circle();
System.out.println("Area of circle: " + figref.area(10.0,5.0));
figref = new triangle();
System.out.println("Area of triangle: " + figref.area(2.0,0.0));
}
}