-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathprogram.js
More file actions
57 lines (46 loc) · 1.19 KB
/
Copy pathprogram.js
File metadata and controls
57 lines (46 loc) · 1.19 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
`class is the blurprint used for object creation.
* class B inherits properties and methods from parent class A.
* And Class B overwrites fun() method.`
class A {
constructor (name, age) {
this.name = name;
this.age = age;
}
fun() {
console.log(`Saying hello to ${this.name}`);
}
}
class B extends A {
constructor (name, age, gender) {
super(name, age);
this.gender = gender;
// this.fun();
}
fun() {
console.log(`Saying hello to ${this.name} from B`);
}
fun2() {
console.log(`Saying hello to ${this.name} from B fun 2`);
}
}
class C extends B {
constructor (name, age, gender, section) {
super(name, age, gender);
// this.name = "fixed";
this.section = section;
}
fun() {
console.log(`Saying hello to ${this.name} from C`);
}
}
let instance = new A("demo", 20);
let instance1 = new B("demo", 20, "male");
let instance2 = new C("Cclass", 11, "abc", "c");
console.log(instance1.name);
console.log(instance1.gender);
instance1.fun();
console.log(instance2.name);
console.log(instance2.gender);
instance2.fun();
instance2.fun2();
console.log(A.prototype);