Ads Sponsored By Google :)

Saturday, 12 January 2013

Types of Inheritance in java with examples with multiple|hybird|hierarchical


inheritance in java multiple inheritance in java inheritance in java with example inheritance example in javaexample of inheritance in java multiple inheritance in java with example types of inheritance in java types of inheritance in java with example inheritance examples in java hybrid inheritance in java hierarchical inheritance in java inheritance examples in java

Inheritance:
          Inheritance is one of the object oriented programming principle. By using this concept allows code reuse in Object oriented programming language. A long with Abstraction, Polymorphism, dynamic binding and inheritance forms the basis of Object oriented programming. By using inheritance one class inherits  all non private data members into another class. However in our real life relationship would exists between parent and child in that manner relationship would exists between two class in java. In what manner in our real life surname , qualities are inherits in that way only data members inherits.

Types of  Inheritance in Java

Definition:
        The process of obtaining the data members and methods from one class to another class   is known as inheritance.                                                                                                                                                                                                                                                                                                                                                                                                                                                       
1)  The concept of inheritance is also known as reusability/subclassing/extendable classes.                 
2)  If a class is given data members and methods to another class is known as base /super         /parent class.
3)  If class is getting features from base class then that class is known as derived /sub class.                                  
4)  Data members and methods of class is known as features.

OOPs Concepts With Real Time Examples

Benefits or Advantages of inheritance / reusability:
     If we develop an application by using concept of inheritance then we benefits as application development time is less, application memory space is less, application execution time is less, application performance is improved and redundancy of code is reduced.

Types of inheritance in java
1)      Single inheritance
2)      Multi – level inheritance
3)      Hierarchical inheritance
4)      Multiple inheritance
5)      Hybrid inheritance
Inheritance


    1) Single inheritance: A single inheritance is one in which there exists single base class and single derived class.

    2) Multi-level inheritance: Multi level inheritance is one in which their exists a single base class, single derived class and multiple intermediate base classes.

    3) Hierarchical inheritance: Hierarchical inheritance is one in which their exists single base class and multiple derived classes.

    4) Multiple Inheritance: Multiple inheritance is one in which their exists multiple base classes and single derived classes.

    5) Hybird Inheritance : Hybird inheritance is equal to combination of any available inheritance types.   
From the above inheritances multiple inheritance is supported in java by using only interfaces concept.

Points to remember regarding inheritance:
          
         1)      Extends is a keyword used for inheriting the features of base class into derived class.
        
         2)      In java programming one derived class can extends only one base class because java programming  does not support multiple inheritance through the concept of classes. But it can be supported through the concept of interfaces.

        3)      In inheritance  when we create an object of bottom derived class first we get memory space for top most base data member, second we get memory space for intermediate class data members, at last we get the memory space for bottom most derived  class data members.
      
       4)      If we do not want to give features to derived class then definition of base class must be made as final. Hence final base classes never participates in inheritance.
     
       5)      If we do not want to give some features of base class through the derived class then such features of base class must be made as private. In other words private features of base class never visible in context of derived class.

      6)       Constructors of one class never inherited to another class.

      7)   Oject of derived class can access the detail support features which are present in the base class but an object of base class never access details of derived class.

      8)      For each and every class in java their exists an implicit predefined super class known as java.lang.Object.
         
          



Why Multiple Inheritance makes Java is Not Pure Object Oriented Programming Language ?


Java OOPs Concepts with Real Life Examples


Object Oriented Programming Principles Are :

1)      Class
2)      Object
3)      Data Abstraction
4)      Data Encapsulation
5)      Inheritance
6)      Polymorphism
7)      Dynamic Binding





2 comments:

LinkWithin