-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqb16.java
More file actions
59 lines (45 loc) · 1.05 KB
/
Copy pathqb16.java
File metadata and controls
59 lines (45 loc) · 1.05 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//QB-16
abstract class shape {
public abstract double area();
}
class triangle extends shape {
private double b;
private double h;
public triangle(double b, double h) {
this.b = b;
this.h = h;
}
public double area() {
return 0.5 * b * h;
}
}
class rectangle extends shape {
private double l;
private double w;
public rectangle(double l, double w) {
this.l = l;
this.w = w;
}
public double area() {
return l * w;
}
}
class circle extends shape {
private double r;
public circle(double r) {
this.r = r;
}
public double area() {
return Math.PI * r * r;
}
}
class Main {
public static void main(String[] args) {
triangle t = new triangle(2, 4);
rectangle r = new rectangle(4, 6);
circle c = new circle(2);
System.out.println("Area of Triangle is: " + t.area());
System.out.println("Area of Rectangle is: " + r.area());
System.out.println("Area of Circle is: " + c.area());
}
}