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());

মন্তব্যসমূহ

এই ব্লগটি থেকে জনপ্রিয় পোস্টগুলি

React Js Cards (Props, Array, Mapping, Rendaring)

React JS - Hooks

React Js - Form Submit, Input