Inheritance in java
Generally the inheritance is a topic under oops concept where one class(base) is derived into several classes(derived). The In Single Inheritance sub class/child class/derived class inherits “only one” parent class properties/variables and behaviors/methods thus enable reusability and as well adding new behaviors or modifying existing behaviors. ^ | In inheritance child class must point to parent class, but not parent class to sub class. We must say Sub Class B is derived from Parent Class A. In Multi-Level Inheritance each sub class derives from only one super class at a time, that super class again derives from only one more super class at a time. D d=new D(); In Hierarchial Inheritance a class can be derived into any number of sub classes. Hybrid Inheritance is a combination of hierarchical and multiple inheritance. D Imp Point: Java supports only multi-level inheritance. Hence in Java each class can derive from only one super class at a time. class A { } class B extends A { } class C extends B { } class D { } Examples on assigning sub class objects to super class references. Remember only common functions can be called. Types of Inheritance are :
Originally published at https://techchannelwithdsk.blogspot.com.