Basic Concept In TypeScript Day 10
A constructor is a special method which will be called whenever we create new objects. And generally used of initializing the class members.
The constructor method is always defined with "constructor" keyword.
The members of the class in a constructor are accessed using "this" keyword.
Syntax :
In TypeScript, we can use common object-oriented patterns. One of the most fundamental patterns in class-based programming is being able to extend existing classes to create new ones using inheritance.
- Single Inheritance
- Multilevel Inheritance
- Multiple Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance.
Single inheritance can inherit properties and behavior from at most one parent class.
It allows a derived/subclass to inherit the properties and behavior of a base class that enable the code reusability as well as we can add new features to the existing code.
The single inheritance makes the code less repetitive.
When a derived class is derived from another derived class, then this type of inheritance is known as multilevel inheritance.
Thus, a multilevel inheritance has more than one parent class.
It is similar to the relation between Grandfather, Father, and Child.
By default, all members of a class in TypeScript are public. All the public members can be accessed anywhere without any restrictions.
The private access modifier ensures that class members are visible only to that class and are not accessible outside the containing class.
Comments
Post a Comment