-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestShape.java
More file actions
48 lines (36 loc) · 943 Bytes
/
Copy pathTestShape.java
File metadata and controls
48 lines (36 loc) · 943 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
abstract class Shape {
abstract double calculate_area();
void display_info() {
System.out.println("This is a Shape");
}
}
class Circle extends Shape {
double r;
Circle(double r) {
this.r = r;
}
double calculate_area() {
return 3.14 * r * r;
}
}
class Rectangle extends Shape {
int l, b;
Rectangle(int l, int b) {
this.l = l;
this.b = b;
}
double calculate_area() {
return l * b;
}
}
class TestShape {
public static void main(String[] args) {
// Shape s = new Shape(); // This will give compile error
Circle c = new Circle(5);
Rectangle r = new Rectangle(4, 6);
c.display_info();
System.out.println("Circle Area: " + c.calculate_area());
r.display_info();
System.out.println("Rectangle Area: " + r.calculate_area());
}
}