This & Super Keyword

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

This and Super keyword

GAURAV
1. This keyword
What is this keyword ?
In java, this is a reference variable that refers to the current object.

state
this
behaviour

reference variable
object
Usage of this keyword

 this can be used to refer current class instance variable.


 this can be used to invoke current class method.
 this() can be used to invoke current class constructor.
to refer current
class instance
variable

1 ashish 4500.0

2 vinay 7500.0
to invoke current
class method

invoked B

Invoked A
to invoke current
class constructor

1 vinay Btech 0.0

2 ashish bsc 25000.0


2. Super Keyword
What is super keyword ?
The super keyword is a reference variable which is used to refer immediate parent class object.

Usage of super keyword :


super can be used to refer immediate parent class instance variable.
super can be used to invoke immediate parent class method.
super() can be used to invoke immediate parent class constructor.
To refer
immediate
parent class
instance variable

black

white
to invoke parent
class method

Animal is eating

Dog is eating

Dog is barking
to invoke parent
class constructor

Parent Constructor part is


created

Child class constructor is


created
this and super
keyword used in
this program

1 Ashish 45000.0
Khatam…….

You might also like