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:
name
parameter and initializes the name
property.play
method.Employee Class:
Person
class.name
and an id
parameter, and initializes the id
property.Designer Class:
Employee
class.name
and an id
parameter.design
method.Developer Class:
Employee
class.name
and an id
parameter.coding
method.Creating instances and invoking methods:
Developer
and Designer
.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()
Have you ever wanted to talk to a friendly, smart robot that helps you with…
DeepSeek AI is becoming a friendly and powerful new tool in the world of artificial…
Do you want to become an expert in Spring Boot CRUD operations? This comprehensive tutorial…
Modern websites must have a navigation bar that is clear and responsive. FlexBox CSS is…
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…
The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…