Categories: Uncategorized

Mastering JavaScript OOP Inheritance

Inheritance in JavaScript using classes. You have a Person class as the superclass, an Employee class  that extends Person, and two subclasses (Designer and Developer)

Person Class:

  • it has a constructor that takes a name parameter and initializes the name property.
  • Defines a play method.

Employee Class:

  • Extends the Person class.
  • it has a constructor that takes a name and an id parameter, and initializes the id property.

Designer Class:

  • Extends the Employee class.
  • it has a constructor that takes a name and an id parameter.
  • Defines a design method.

Developer Class:

  • Extends the Employee class.
  • it has a constructor that takes a name and an id parameter.
  • Defines a coding method.

Creating instances and invoking methods:

  • Creates instances of Developer and Designer.
  • Calls the play, coding, and design methods.
class Person     //super class 
{
    constructor(name)
    {
        this.name=name
    

    this.play=()=>{
        console.log("playing");
    }
}
}

//sub class
class Employee extends Person{
    constructor(name,id)
    {
        super(name)
        this.id=id
     }
}

class Designer extends Employee{
    constructor(name,id)
    {
        super(name,id)
        this.design=()=>{
            console.log("Designing.......")
        }
        
     }
}

class Developer extends Employee{
    constructor(name,id)
    {
        super(name,id)
        this.coding=()=>{
            console.log("Coding.......")
        }
        
     }
}

const developer = new Developer("java codinggg",1)
const designer = new Designer("UX Design",1)

developer.play()
developer.coding()
designer.design()

 

admin

Recent Posts

Fish Inventory Shop Management System in Angular

This article explain how to make a Fish Inventory Management App in Angular.this app explain…

5 days ago

Fish Inventory Management with React

Introduction to Fish Inventory Management In the aquaculture industry, managing fish inventory is crucial for…

6 days ago

Java GUI CRUD for Beginners

Introduction to Java GUI CRUD Java is a powerful programming language widely used for building…

6 days ago

Creating Beautiful Login Form Design Using React

Introduction to Login Form Design Designing an effective and beautiful login form is crucial for…

2 weeks ago

Creating Responsive Login Form with React

Introduction In today creating a responsive login form is essential for providing a seamless user…

2 weeks ago

Master React Inventory Management System Development

Introduction to Inventory Management Systems In today's fast-paced digital environment, businesses require efficient inventory management…

2 weeks ago