Cs3391 – Object Oriented Programming - Demo
Cs3391 – Object Oriented Programming - Demo
ENGINEERING
CS3391 – OBJECT
ORIENTED
PROGRAMMING
Inheritance and Types
VASANTH SRIDHAR - ME
OOPS CONCEPTS
• We can access one class property from another class by using extends keyword
• It is an important part of oops
Why to use Inheritance
• To reduce the number of object creation
• So that the memory wastage is low
• We can reuse the code where ever we need using extends call using current class object itself
• Parent class – gives property to child class
• Child class – accepts property from parent class
Types of inheritance
• Single Inheritance
• Multilevel Inheritance
• Multiple Inheritance
• Hierarchial Inheritance
• Hybrid Inheritance
Single Inheritace
More than one parent class accessing the class in a tree level structure (B extends A then C extends B),
it is a level by level inheritance
Multiple Inheritance
• More than one parent class accessing the child class parallelly at a time (C extends A,B)
NOTE:
• Multiple inheritance is not supported in java through class using extends keyword
• Because it shows syntax error in compile time due to the priority issue (ambiguity
problem)
• We can achieve this through the interface by using implement keyword
Priority issue/Ambiguity problem
It is the problem arises when the two parent class gives their property to their one child class at a same time,
at that time the child class will get confuse on which parent property to get(prioritize) first.
Hierarchial inheritance
Combination of one parent and more than one child (B extends A then C extends A)
Hybrid inheritance