-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolymorphism.js
More file actions
38 lines (34 loc) Β· 757 Bytes
/
polymorphism.js
File metadata and controls
38 lines (34 loc) Β· 757 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
// Hazrat Ali
// University Of Scholars
class Circle {
constructor(radius){
this.radius = radius;
}
area() {
return Math.PI * Math.pow(this.radius, 2);
}
}
class Rectangle {
constructor(width, height){
this.width = width;
this.height = height;
}
area() {
return this.height * this.width;
}
}
class Triangle {
constructor(base, height){
this.base = base;
this.height = height;
}
area() {
return this.base * this.height/2;
}
}
const shapes = [new Circle(10), new Rectangle(10, 5), new Circle(20), new Triangle(10, 10)];
for (let i = 0; i < shapes.length; i++) {
const shape = shapes[i];
console.log(shape.area());
// polimorphism
}