-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalAbMethod.java
More file actions
40 lines (34 loc) · 1.1 KB
/
Copy pathFinalAbMethod.java
File metadata and controls
40 lines (34 loc) · 1.1 KB
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 Geometry {
abstract void rectangle_area(int h, int w);
abstract void triangle_area(int b, int h);
abstract void circle_area(double r);
abstract void square_area(int s);
final void rectangle_perimeter(int h, int w) {
int perimeter = 2 * (h + w);
System.out.println("Perimeter of rectangle is " + perimeter);
}
}
class Easy extends Geometry {
void rectangle_area(int h, int w) {
System.out.println("Area of rectangle is " + h * w);
}
void triangle_area(int b, int h) {
System.out.println("Area of triangle is " + (b * h) / 2);
}
void circle_area(double r) {
System.out.println("Area of circle is " + 3.14 * r * r);
}
void square_area(int s) {
System.out.println("Area of square is " + s * s);
}
}
public class FinalAbMethod {
public static void main(String[] args) {
Easy e = new Easy();
e.rectangle_area(5, 10);
e.triangle_area(10, 5);
e.circle_area(5);
e.square_area(5);
e.rectangle_perimeter(5, 10); // This line will now work correctly
}
}