-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ11.java
41 lines (38 loc) · 828 Bytes
/
Q11.java
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
// 11. Design a java program to show dynamic polymorphism.
class MyArea {
void area() {
System.out.println("A concrete function called Area()");
}
}
class SqArea extends MyArea {
double side;
SqArea(double s) {
side = s;
}
void area() {
double area;
area=side*side;
System.out.println("Area of Square = " + area);
}
}
class RectArea extends MyArea {
double l,b;
RectArea(double l, double b) {
this.l = l;
this.b = b;
}
void area() {
double area;
area=l*b;
System.out.println("Area of Rectangle = " + area);
}
}
class Main {
public static void main(String a[]) {
MyArea ma;
ma=new SqArea(10);
ma.area();
ma=new RectArea(10, 2);
ma.area();
}
}