Introduction:
•Inheritance is one of the corner stone’s of Java language.
•Using inheritance we can arrange the classes in a hierarchy.
•In Inheritance, all the common characteristics of objects/items are specified in a general class.
•A specialized class will inherit/derive the general class in which the common characteristics are specified and adds its own unique properties.
•In Java terminology, a class which is being inherited is known as a super class or base class or parent class.
•A class which inherits a super class is known as a sub class or derived class or child class.
•So, a subclass is a specialized version of a superclass.
•A subclass adds its own unique properties in addition to the common characteristics derived from the superclass.
•In Java, inheritance is implemented using the “extends” keyword.
Member Access and Inheritance:
•A subclass can access all the members of the superclass except private members because private members are accessible only in the class in which they are declared.
•A subclass can access all other members of the superclass which are declared as public, protected and default.
Advantages of Inheritance:
•Inheritance makes it easy to maintain and modify existing code.
•Provides reusability.
•Saves time and effort.
•Data hiding from subclasses.
Disadvantages of Inheritance:
•Multiple inheritance: If all the classes in multiple inheritance are having the same data members, then the compiler will be in ambiguous situation of which member to invoke.
•The subclasses are tightly coupled with the superclass.
•Subclasses are restricted to implement the behavior of superclass.
•Inheritance is one of the corner stone’s of Java language.
•Using inheritance we can arrange the classes in a hierarchy.
•In Inheritance, all the common characteristics of objects/items are specified in a general class.
•A specialized class will inherit/derive the general class in which the common characteristics are specified and adds its own unique properties.
•In Java terminology, a class which is being inherited is known as a super class or base class or parent class.
•A class which inherits a super class is known as a sub class or derived class or child class.
•So, a subclass is a specialized version of a superclass.
•A subclass adds its own unique properties in addition to the common characteristics derived from the superclass.
•In Java, inheritance is implemented using the “extends” keyword.
Member Access and Inheritance:
•A subclass can access all the members of the superclass except private members because private members are accessible only in the class in which they are declared.
•A subclass can access all other members of the superclass which are declared as public, protected and default.
Advantages of Inheritance:
•Inheritance makes it easy to maintain and modify existing code.
•Provides reusability.
•Saves time and effort.
•Data hiding from subclasses.
Disadvantages of Inheritance:
•Multiple inheritance: If all the classes in multiple inheritance are having the same data members, then the compiler will be in ambiguous situation of which member to invoke.
•The subclasses are tightly coupled with the superclass.
•Subclasses are restricted to implement the behavior of superclass.
This comment has been removed by the author.
ReplyDelete