Skip to content

JS Class Inheritance Example

  class People_Info{
    constructor(id,name,surname,age,salary){
      this.id = id;
      this.name = name;
      this.surname = surname;
      this.age = age;
      this.salary = salary;
    };
    print(){
      console.log(`
      id: ${this.id}
      name: ${this.name}
      surname: ${this.surname}
      age:${this.age}
      salary: ${this.salary}`);
    };
  };

  let jack = new People_Info(1,"Jack","Queen",27,6000);
  jack.print();

  let maria = new People_Info(2,"Maria","Allen",30,7800);
  maria.print();

id: 1
name: Jack
surname: Queen
age:27
salary: 6000

id: 2
name: Maria
surname: Allen
age:30
salary: 7800

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: