-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.java
More file actions
41 lines (33 loc) · 924 Bytes
/
Shape.java
File metadata and controls
41 lines (33 loc) · 924 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
interface Shape{
public float PI = 3.14f;
public float area();
public float perimeter();
}
class Circle implements Shape{
public int radius = 5;
public float area(){
return PI * radius * radius;
}
public float perimeter(){
return 2 * PI * radius;
}
}
class Rectangle implements Shape{
int length = 5, breath = 6;
public float area(){
return length * breath;
}
public float perimeter(){
return 2 * (length + breath);
}
}
public class Shapes7{
public static void main(String args[]){
Circle c = new Circle();
Rectangle r = new Rectangle();
System.out.println("Area of circle : " + c.area());
System.out.println("Perimeter of circle : " + c.perimeter());
System.out.println("Area of rectangle : " + r.area());
System.out.println("Perimeter of rectangle : " + r.perimeter());
}
}