Javascript opps
class student{//creating of class
constructor(name,age,cls){ //creating constractors
this.name=name;
this.age = age;
this.cls = cls;
}
biodata(){ // creating methods
return `Hi my name is ${this.name}, my age is ${this.age}, I read in ${this.cls}`;
}
}
//let obj1 = new student("shoyeb",18,"BCA");//creating a object
//obj1.biodata(); //calling the method
class player extends student{
//players class is inheriting the property of the student class.
//extends is used to inherit a class
constructor(name,age,cls,game){
super(name,age,cls); //super keyword allows you to access the properties of parent class
this.game=game;
}
biodata2(){ // creating methods
// console.log(`Hi my name is ${this.name}, my age is ${this.age}, I read in ${this.cls}, I play ${this.game}`);
return `${super.biodata()}. I playes ${this.game}`; //we can use the parent method with super keyword
}
}
let obj2 = new player("shoyeb",19,"bca","cricket");
console.log(obj2.biodata2());
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন