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

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

2 weeks ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

1 month ago

Build Your First Responsive Login Form Using HTML and CSS FlexBox

Creating a responsive login form is a crucial skill for any web developer. In this…

1 month ago

Build Crud API with Laravel 12

In this tutorial will teach  Laravel 12 CRUD API  by step. Laravel  10 CRUD Application …

1 month ago

laravel 12 image upload tutorial

In this lesson we talk about laravel 12 image uploading and display the image step…

2 months ago

Laravel 12 CRUD Application

In this tutorial will teach Laravel 12 CRUD Application step by step. Laravel  12 CRUD…

2 months ago