3.2 Es6 OOPs
3.2 Es6 OOPs
#JavaScript Notes
Oops Concept
Class
Encapsulation
Inheritance
Polymorphism
class Car{
constructor(carname){
this.name = carname;
}
get CarName(){
return this.name;
}
set CarName(x){
this.name = x;
}
}
//Object
myobj = new Car("BMW");
console.log(myobj.CarName);
//Assign
myobj.CarName = "Audi";
//Get
console.log(myobj.CarName);
myobj.CarName = "Honda";
//Get
console.log(myobj.CarName);
Super Class:The class whose properties are inherited by sub class is called
Parent class or Base class or Super class.
greet() {
console.log(`Hello ${this.name}`);
}
}
constructor(name) {
console.log("Creating student class");
// call the super class constructor and pass in the name parameter
super(name);
}
This means that if the class is inherited from its parent class and both have
the same methods, so the child class methods can be overridden or rewritten
according to its functionality.
// parent class
class Person {
greet() {
console.log("Hello, This is Person class's greet method...");
}
}
// inheriting parent class
class Student extends Person {
greet() {
//Calling Parent class method
super.greet();
console.log("Hello, This is Student class's greet method...");
}
}
//Object of Student Class
let student1 = new Student();
student1.greet();
www.aptutorials.com
https://www.youtube.com/user/Akashtips
www.akashsir.com
Rating Us Now
Just Dial
https://www.justdial.com/Ahmedabad/Akash-Technolabs-
Navrangpura-Bus-Stop-Navrangpura/079PXX79-XX79-
170615221520-S5C4_BZDET
Sulekha
https://www.sulekha.com/akash-technolabs-navrangpura-
ahmedabad-contact-address/ahmedabad
Connect With Me
# Social Info
Akash.padhiyar
Akashpadhiyar
Akash Padhiyar
#AkashSir Akash_padhiyar
+91 99786-21654
www.akashsir.com
www.akashtechnolabs.com #Akashpadhiyar
www.akashpadhiyar.com #aptutorials
www.aptutorials.com