Inheritance complete explanation
Inheritance is key concept in Java.It is almost everywhere in Java.It is nearly impossible to write the tiniest Java program without Inheritance.We all create classes in Java programs.Whenever we create a Java class we automatically inherit all of class object methods.
Inheritance has two key concepts:-
1.Code Reuse
2.Polymorphism
Inheritance means someone or something derives a set of attributes and properties from someone or something else,like lucky inherited diabetes from his father,Craig inherited his father's business.
Inheritance is one of the ways of implementing abstraction.As we know that abstraction is all about describing the essential detail and ignoring non-essential details.
Note:-
1.When a class inherits a set of attributes and behaviours from another class ,then class that inherits is called subclass and class from which attributes and behaviours are inherited is called super class.
2.An abstract superclass is a conceptual class which does not contain any code in particular but acts as a base from which other class inherits properties.
3.When a class inherits from two or more superclasses then it is be showing multiple inheritance.
Complete Example:-

Look at above figure ,In the given hierarchy,we have classes named Mammals,Dogs,Humans,Cats,Lions,Tigers,Leopards .Mammals class has following properties:-
1.They are vertebrates
2.They are warm blooded
3.They have hairs on their body
From the hierarchy it is clear that Dogs,Cats and Humans also have these characteristics too.In technical terms we can say that above mentioned classes have inherited these attributes from Mammal class.
The description given above does not contain any vertebral nature of skeletal system,it being warm blooded,its ears,hairs on the body and other features have already been described for the class Mammals and since cats inherit these features from Mammals,only the details specific to the cats need to mentioned in its class.
Suggested Links:-
Object Oriented Concepts
Why Java Not support multiple Inheritance


















0 comments:
Post a Comment
Post a Comment