-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterfax.java
More file actions
54 lines (43 loc) · 1.09 KB
/
Interfax.java
File metadata and controls
54 lines (43 loc) · 1.09 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
52
53
54
interface Shape {
double area();
double perimeter();
}
class Circle implements Shape {
double radius;
public Circle(double radius) {
this.radius = radius;
}
@Override
public double area() {
return (Math.PI) * radius * radius;
}
@Override
public double perimeter() {
return 2 * (Math.PI) * radius;
}
}
class Rectangle implements Shape {
double length, breadth;
Rectangle(double length, double breadth) {
this.length = length;
this.breadth = breadth;
}
@Override
public double area() {
return length * breadth;
}
@Override
public double perimeter() {
return 2 * (length + breadth);
}
}
public class Interfax {
public static void main(String[] args) {
Circle cobj = new Circle(10);
System.out.println("Area " + cobj.area());
System.out.println("Perimeter " + cobj.perimeter());
Rectangle robj = new Rectangle(10, 20);
System.out.println("Area " + robj.area());
System.out.println("Perimeter " + robj.perimeter());
}
}