Sunday, June 22, 2014

Inheritance Oop

Inheritance is a powerful feature of object oriented programming (oop's). It is a  mechanism of sharing attributes and operations among classes. It allows new classes to be derived from existing ones. The derived class (sub class) inherits all the methods and variables of the base class (super class).
In above figure-
  • Class A is the super class of B
  •  Class B is a sub class of A
  • Class B is the super class of C, D and E
  • Class C, D and E are sub class of B

Syntax: -

class Subclass_name extends Superclass_name

     {

          //methods

      }

      

 Example: -

public class SuperObject

  {

    public int length () { ... }

  }

 public class SubObject extends SuperObject

  {

  }  

Types of Inheritance :-

  1. Single Level: - Single sub class is created from a single super class called single level inheritance.
  2. Hierarchical: - More then one sub class are created from a single super class, then that inheritance is called hierarchical inheritance.
  3. Multi Level: - Sub class is created from another Super class, than that inheritance is called as multi level.
  4. Multiple: - Sub class is created from more than one sub class, than that inheritance is called as multiple inheritance.
Note :- Multiple inheritance is not supported in JAVA and Dot Net due to complexity.

No comments:

Post a Comment