forked from anisul-Islam/java-documentation-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
47 lines (36 loc) · 779 Bytes
/
Copy pathTest.java
File metadata and controls
47 lines (36 loc) · 779 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
class Shape {
double dim1, dim2;
Shape(double dim1, double dim2) {
this.dim1 = dim1;
this.dim2 = dim2;
}
double area() {
return 0;
}
}
class Rectangle extends Shape {
Rectangle(double dim1, double dim2) {
super(dim1, dim2);
}
double area() {
return dim1 * dim2;
}
}
class Triangle extends Shape {
Triangle(double dim1, double dim2) {
super(dim1, dim2);
}
double area() {
return 0.5 * dim1 * dim2;
}
}
class Test {
public static void main(String[] args) {
Shape s = new Shape(0, 0);
System.out.println("Shape Area: " + s.area());
s = new Rectangle(10, 20);
System.out.println("Rectangle Area: " + s.area());
s = new Triangle(10, 20);
System.out.println("Triangle Area: " + s.area());
}
}