-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
33 lines (33 loc) · 809 Bytes
/
Main.java
File metadata and controls
33 lines (33 loc) · 809 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
abstract class Shape {
double dim1;
double dim2;
Shape(double d1, double d2) {
dim1 = d1;
dim2 = d2;
}
abstract double area();
}
class Rectangle extends Shape {
Rectangle(double length, double width) {
super(length, width);
}
double area() {
return dim1 * dim2;
}
}
class Triangle extends Shape {
Triangle(double base, double height) {
super(base, height);
}
double area() {
return 0.5 * dim1 * dim2;
}
}
public class Main {
public static void main(String[] args) {
Shape rectangle = new Rectangle(10, 5);
Shape triangle = new Triangle(6, 8);
System.out.println("Area of Rectangle: " + rectangle.area());
System.out.println("Area of Triangle: " + triangle.area());
}
}