Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Javascript/program-15/program.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);