-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
54 lines (49 loc) · 903 Bytes
/
Main.java
File metadata and controls
54 lines (49 loc) · 903 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
45
46
47
48
49
50
51
52
53
54
abstract class shape{
abstract double calculateArea();
}
class Rectangle extends shape{
double length;
double bredth;
Rectangle(double length, double bredth){
this.length = length;
this.bredth = bredth;
}
double calculateArea(){
return length*bredth;
}
}
class Circle extends shape{
double radius;
Circle(double radius){
this.radius = radius;
}
double calculateArea(){
return Math.PI * radius * radius;
}
}
class Square extends shape{
double side;
Square(double side){
this.side = side;
}
double calculateArea(){
return side*side;
}
}
class Triangle extends shape{
double base;
double height;
Triangle(double base, double height){
this.base = base;
this.height = height;
}
double calculateArea(){
return 0.5 * base * height;
}
}
class Main{
public static void main(String[] args){
Circle c = new Circle(4);
System.out.println(c.calculateArea());
}
}