Lecture 5
Lecture 5
Class B {
Void m1() Sub Class
{} }
Class C extends A
{ // line of code}
Class D extends A
{ // line of code}
Hierarchical Inheritance Contd..
Hierarchical Inheritance Contd..
Hybrid
• It is a mix of two or more types of inheritance.
• Combination of Hierarchical + Multi-level
• Combination of Single + Hierarchical
• Combination of Single + Multi-level
• Access modifiers
• Access levels (private, public, protected) determine which attributes and
methods are accessible to child classes.
Assignment
• Diamond problem in inheritance.
Interview Questions
1. In java Multiple inheritance is achieved via _______ .
2. How can we access any variable/method of Super class via object of
sub class?
Super keyword
• It is used when we want to call variables, methods and constructor of
super class via object of a sub-class.
Note:
Whenever the super class and sub-class variables or method names are
same then Super keyword is used to refer to the variables/methods of
Super class.
Use of Super Keyword to Access
Variables
Use of Super Keyword to Access
Methods
Use of Super Keyword to Access
Constructors