Inheritance - TypeScript is supports the concept of Inheritance.
Inheritance has ability of a program to extend existing classes to create new ones.
The extended class is called parent class or super class and the newly created classes are called child class or sub class.
Inheritance can be classified as -
Inheritance can be classified as -
1. Single - every class
can at the most extend from one parent class
2. Multiple - doesn’t
support multiple inheritances in TypeScript.
3. Multi-level
3. Multi-level
A class captains the Public, Private, Protected and Read-only modifiers and Public by default.
You can see the below example, the class User and each members are public by default.
Example as,
class Employee { empName: string; constructor(name: string) { this.empName = name; } salary(salary: number = 10000) { console.log('Hello, ' + this.empName + ' Your Salary -' + salary); } } class Employer extends Employee { constructor(empName: string) { super(empName); } salary(salary = 20000) { super.salary(salary); } } let empSal = new Employee("Anil"); console.log(empSal.salary()); console.log(empSal.salary(40000));
I hope you are enjoying with this post! Please share with you friends. Thank you!!