Q: What is inheritance in java?
Q: Different level of inheritance in java?
Q: How to implement inheritance in java?
Q: What is hybrid inheritance?
Q: What is multiple inheritance?
Inheritance is a mechanism by which we can inherits some existing features of another class.
Inheritance consist of 2 or more classes.
One is super class and another is subclass Super class is that class from which we inherits some features. It is also called as parent class or root class. whereas Subclass is that which inherit feature from super class. It is also called as child class Inheritance is a relationship between subclass and super class.
Consider a example of vehicles , a 4 wheeler vehicle, cars, maruti and alto. 4 wheeler vehicle is extended from vehicle then vehicle is super class whereas 4 wheeler vehicle is subclass. Similarly cars is extended from 4 wheeler vehicle, and maruti and alto is extended from cars. Vehicles is super class of all of this whereas , a 4 wheeler vehicle, cars, maruti and alto are subclass. As we all have the same ancestors similarly inheritance works.
We can inherit a class by simply writing following code: class Alto extends cars
TYPE OF INHERITANCE
public class A
class B extends A
public static void main(String args)
B obj=new B();