INHERITANCE AND CONSTUCTOR CONCEPTS

10th Day                                                                                                                          
                                                                                                                   
 Hey Guys ,I hope that you are enjoying with my blogs writing and today's we 
 will cover some concepts:
                                                    



          INHERITANCE :   
    • Inheritance is an aspect of OOPs languages.
    • which provides the ability of a program to create a new class from an existing class.
    • The class whose members are inherited is called the base class, and the class that inherits those members is called the derived/child/subclass. In child class, we can override or modify the behaviors of its parent class.
    • Syntax:
                    Parent class :
                          
                          class <Class_name>
                                {
                                   // methods and fields
                                 }
    •  Example:
                      

                            Child class:
                          class sub_class_name extends super_class_name  
                           {  
                              // methods and fields  
                           {
    •  Example:
                    


    • We can use it for Code Reusability.
    • We can use it for Method Overriding.
    • This is called IS RELATIONSHIP i.e. Customer IS A CHILD OF  Lead.
                    



    • Using import and export method we have created parent-child relationship.
    •  Example:
                   




         TYPES OF INHERITANCE:  
    • Single Inheritance: it can inherit properties and behavior from at most one parent class.
    • Multilevel Inheritance: In this case a derived class is derived from another derived class.
    • Multiple Inheritance :When an object or class inherits the characteristics and features form more than one parent class.
    • Hierarchical Inheritance:  In this case, More than one subclass is inherited from a single base class.
    • Hybrid Inheritance: In this case, A class inherits the characteristics and features from more than one form of inheritance.




                 TypeScript Inheritance

   


 
           CONSTRUCTOR:    
    • A Constructor is a special type of function of typescript class and it will be automatically invoked when the first object of class is created.
    • TypeScript only allows one constructor implementation.
    • Suppose, In above Example we have required default values like address or anything.
    • For Example: We have created two  class Lead & Customer  in Customer.ts .
    • Customer.ts: 
                


    • Now here ,we have created  Client.ts which will invoke Customer and Lead class :
              


    • After Compilation: Using tsc -- init
               


    • So here tsconfig.json file has been created successfully like Example:

                       

    
    •  Just Run Client.js file through teminal: node Client.js  address will give as output.
             


    • Suppose if it has constructor in parent class then first fire it.
             Access Modifiers public private and protected :             :
    • Public: It is accessible outside or anywhere the class.
    • Private: it is only accessible inside the class.
    • Protected: It is only accessible in inherited classes and own classes we can't access outside.

                   


  • So friend If you have any mistakes in any articles you can send me on my email:1809raushan@gmail.com.

                                                                                Thank You...
                                                   


               




No comments:

Post a Comment