Day 9 : TypeScript

 

Constructor :

  • Constructor is a special type of  method or function which is called at the time of object creation.
  • The constructor method is always defined with "constructor" keyword.
  • The class always having a constructor is not needed or necessary.
  • The members of the class in a constructor are accessed using "this" keyword.
  • Syntax :
constructor () {
//statements
                                                              }
  • Example :
    


Access Modifiers :

  • The access modifiers are used for controlling the visibility or availability of its data members.
  • Mainly their are three types of access modifiers :

1) Public :

  • By default, all members or functions of class are public.
  • Public members are accessible anywhere in the program.

2) Private :

  • The private members are accessible only within the class and its child class.
  • If we create a object of private member outside the class, it will give compile error.

3) Protected :

  • The protected members are accessible within class and inherited class.

Example of access modifiers :



Inheritance :

  • Creating a new class(derived class) from existing class(base class) is called as inheritance.
  • The class whose members are inherited is called as parent/base class.
  • The class who inherits those members is called as child/derived class.
  • The "extends" keyword is used in TS for inheritance.
  • We use inheritance for method overriding and code reusability.
  • Their are 5 types of inheritance :
  1. Single Inheritance
  2. Multilevel Inheritance
  3. Multiple Inheritance
  4. Hybrid Inheritance
  5. Hierarchical Inheritance
  • But TS supports only single and multilevel inheritance.

1) Single Inheritance :

  • Deriving a new class from base class is called as single inheritance.
  • The single inheritance inherits the properties of at most one parent class.
  • In single inheritance, the derived class inherits methods of base class as well as add new methods in existing program.

2) Multilevel Inheritance :  

  • Deriving a new class from derived one is called as multilevel inheritance.
  • The multilevel inheritance inherits properties of more than one parent class.
  • In multilevel inheritance, the derived class inherits properties of both derived and base class.

Example :




Thank You!!!

For more understanding watch below video :


JavaScript Day 1 : Day 1

JavaScript Day 2 Global Pollution : Day 2 Global

JavaScript Day 2  Undefined and Hoisting : Day 2 Undefined

JavaScript Day 3 : Day 3

JavaScript Day 4 : Day 4

JavaScript Day 5 : Day 5

JavaScript Day 6 : Day 6

TypeScript Day 7 : Day 7

TypeScript Day 8 : Day 8

Comments

Popular posts from this blog

Day 3 : JavaScript

SQL Concepts-1

ASP .NET Session Management