-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExp71.java
More file actions
40 lines (32 loc) · 837 Bytes
/
Exp71.java
File metadata and controls
40 lines (32 loc) · 837 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
abstract class Shape {
abstract void calculateArea();
}
class Rectangle extends Shape {
double length, width;
Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
void calculateArea() {
double area = length * width;
System.out.println("Rectangle Area: " + area);
}
}
class Circle extends Shape {
double radius;
Circle(double radius) {
this.radius = radius;
}
void calculateArea() {
double area = Math.PI * radius * radius;
System.out.println("Circle Area: " + area);
}
}
public class Exp71 {
public static void main(String[] args) {
Shape rectangle = new Rectangle(5, 3);
Shape circle = new Circle(4);
rectangle.calculateArea();
circle.calculateArea();
}
}