Inheritance
IFTEKHARUL
ABEDEEN
Contents
● Inheritance
● super keyword
● Object class
Inheritance
01
Inheritance
● The process of acquiring properties one
object by another.
● It helps forming new classes using other
classes that have already been defined.
● The new class (child), take over (inherit)
attributes and methods of an existing
class (parent).
Java
● ‘extended’ keyword is used to show the
relationship
● The class that is extended is superclass
aka. parent class, base class, ancestor class
● The class that extends is subclass
aka. child class, derived class, extended class
Java
An object created from the subclass has its own copy
of all the non static fields defined in its superclass.
Benefits
● Inheritance supports the concept of hierarchical
classification.
● It helps organizing and structuring our software.
● It helps reuse our code with little to no
modification.
super
02
why?
The super keyword in java is a reference variable
that is
used to refer immediate parent class object.
Java
● Whenever we create an instance of subclass, the
instance of parent class is created implicitly
i.e. referred by super reference variable.
● Usage of super keyword
I. super() is used to invoke immediate parent
class
constructor.
II. super is used to access members of parent
object.
Java
● Usage of super keyword
I. Access parent class’s instance variable if child
has an
instance variable with same name.
II. super is used to access members of parent
object.
note!
If the constructor doesn’t have super(), compiler
will provide super() as the first statement of the
constructor.
And parent constructor is always executed before
child constructor.
Object class
03
Java
● The Object class is the parent class of all
the classes in java by default. In other
words, it is the topmost class of java.
Src. Java Object Class - Javatpoint
Thank You