Skip to content

Instantly share code, notes, and snippets.

@sagardere
Created May 22, 2018 17:04
Show Gist options
  • Save sagardere/6caa80239cdb38c4a703b1b23da74ccc to your computer and use it in GitHub Desktop.
Save sagardere/6caa80239cdb38c4a703b1b23da74ccc to your computer and use it in GitHub Desktop.
class Animal{
constructor(name , height){
this.name = name;
this.height = height;
}
Hello(){
console.log("Hello from Animal");
}
}
//Extends class Parents/Animal
class Lion extends Animal{
constructor(name , height , color){
super(name , height);//call to super class
this.color = color;//add new parameter
}
Hello(){
super.Hello();
console.log("Hello fron Lion");
}
}
//Here Creating Instances Parent Class/Animal
//when create class instance by default call to constructor.
let king_1 = new Animal();
let king_2 = new Animal('Tiger' , 3.2);
//Creating instance of child class/Lion
let son = new Lion('Dog' , 3.2 ,'red');
son.Hello(); //Hello from Lion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment