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