SlideShare a Scribd company logo
Super Keyword
Super Keyword in Java
• The super keyword in Java is a reference variable which is used to
refer immediate parent class object.
• Whenever you create the object of subclass, an object of parent class is
created implicitly which is referred by super reference variable.
Usage of Java super Keyword
1. super can be used to refer immediate parent class instance variable.
2. super can be used to invoke immediate parent class method.
3. super() can be used to invoke immediate parent class constructor.
1. super is used to refer immediate parent
class instance variable.
• We can use super keyword to access the data member or field of parent
class.
• It is used if parent class and child class have same fields.
Example
class A
{
int a =10;
}
class B extends A
{
int a =20;
void display()
{
System.out.println(a);//prints a of B class
System.out.println(super.a);//prints a of A class
}
public static void main(String x[])
{
B b1= new B();
b1.display();
}
}
Cont…
Output:
20
10
2. super can be used to invoke parent class method
• The super keyword can also be used to invoke parent class method.
• It should be used if subclass contains the same method as parent class.
• In other words, it is used if method is overridden.
Example
class A
{
void display()
{
System.out.println("Class A");
}
}
class B extends A
{
void display()
{
System.out.println("Class B");
super.display();
}
public static void main(String X[])
{
B b1=new B();
b1. display();
}
}
Cont…
Output:
Class A
3. super() can be used to invoke immediate parent class
constructor.
• The super keyword can also be used to invoke the parent class
constructor.
Example
class A
{
A()
{
System.out.println("Class A");
}
}
class B extends A
{
B()
{
super();
System.out.println("Class B");
}
public static void main(String X[])
{
B b1=new B();
}
}
Cont…
Output:
Class A
Class B

More Related Content

PPTX
Modules 333333333³3444444444444444444.pptx
radhikacordise
 
PPT
Super and final in java
anshu_atri
 
PPTX
Java Inheritance - sub class constructors - Method overriding
NithyaN19
 
PPTX
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
PPT
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
AshwathGupta
 
PPT
Super keyword.23
myrajendra
 
PPTX
Inheritance1
Daman Toor
 
PDF
Java keywords
Ravi_Kant_Sahu
 
Modules 333333333³3444444444444444444.pptx
radhikacordise
 
Super and final in java
anshu_atri
 
Java Inheritance - sub class constructors - Method overriding
NithyaN19
 
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
AshwathGupta
 
Super keyword.23
myrajendra
 
Inheritance1
Daman Toor
 
Java keywords
Ravi_Kant_Sahu
 

Similar to BCA Super Keyword.pptx (20)

PDF
Keywords and classes
Ravi_Kant_Sahu
 
PPTX
inheritance.pptx
sonukumarjha12
 
PPTX
Inheritance in Java
Elizabeth alexander
 
PPTX
OCA Java SE 8 Exam Chapter 5 Class Design
İbrahim Kürce
 
PPTX
Inheritance
Daman Toor
 
PPS
Inheritance chepter 7
kamal kotecha
 
PDF
Java inheritance
Hamid Ghorbani
 
PDF
Chapter- 3 Inheritance and Polymorphism-1x4.pdf
joshua211619
 
PPTX
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
RudranilDas11
 
PPTX
Unit3 inheritance
Kalai Selvi
 
PPTX
Chap-3 Inheritance.pptx
chetanpatilcp783
 
PPT
Classes2
phanleson
 
PPTX
Inheritance in Java
Ganesh kumar reddy
 
PPTX
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Sagar Verma
 
PPTX
Basics to java programming and concepts of java
1747503gunavardhanre
 
PPTX
Chap3 inheritance
raksharao
 
PDF
Java Basic day-2
Kamlesh Singh
 
PPTX
Object Oriented Programming Inheritance with case study
MsPariyalNituLaxman
 
PDF
Javascript classes and scoping
Patrick Sheridan
 
PPT
9781439035665 ppt ch10
Terry Yoast
 
Keywords and classes
Ravi_Kant_Sahu
 
inheritance.pptx
sonukumarjha12
 
Inheritance in Java
Elizabeth alexander
 
OCA Java SE 8 Exam Chapter 5 Class Design
İbrahim Kürce
 
Inheritance
Daman Toor
 
Inheritance chepter 7
kamal kotecha
 
Java inheritance
Hamid Ghorbani
 
Chapter- 3 Inheritance and Polymorphism-1x4.pdf
joshua211619
 
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
RudranilDas11
 
Unit3 inheritance
Kalai Selvi
 
Chap-3 Inheritance.pptx
chetanpatilcp783
 
Classes2
phanleson
 
Inheritance in Java
Ganesh kumar reddy
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Sagar Verma
 
Basics to java programming and concepts of java
1747503gunavardhanre
 
Chap3 inheritance
raksharao
 
Java Basic day-2
Kamlesh Singh
 
Object Oriented Programming Inheritance with case study
MsPariyalNituLaxman
 
Javascript classes and scoping
Patrick Sheridan
 
9781439035665 ppt ch10
Terry Yoast
 
Ad

More from sarthakgithub (10)

PPTX
Access Modifiers in Java.pptx
sarthakgithub
 
PPTX
ppt-2.pptx
sarthakgithub
 
PPTX
soumay.pptx
sarthakgithub
 
PPTX
Data Path Design and Bus Organization.pptx
sarthakgithub
 
PPTX
Python Unit II.pptx
sarthakgithub
 
PPTX
OOP-Module-1-Section-4-LectureNo1-5.pptx
sarthakgithub
 
PPT
Flow Control (1).ppt
sarthakgithub
 
PPT
BCA MultiThreading.ppt
sarthakgithub
 
PPTX
BCA Abstraction.pptx
sarthakgithub
 
PPTX
BCA Final Keyword.pptx
sarthakgithub
 
Access Modifiers in Java.pptx
sarthakgithub
 
ppt-2.pptx
sarthakgithub
 
soumay.pptx
sarthakgithub
 
Data Path Design and Bus Organization.pptx
sarthakgithub
 
Python Unit II.pptx
sarthakgithub
 
OOP-Module-1-Section-4-LectureNo1-5.pptx
sarthakgithub
 
Flow Control (1).ppt
sarthakgithub
 
BCA MultiThreading.ppt
sarthakgithub
 
BCA Abstraction.pptx
sarthakgithub
 
BCA Final Keyword.pptx
sarthakgithub
 
Ad

Recently uploaded (20)

PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PDF
Study Material and notes for Women Empowerment
ComputerScienceSACWC
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PPTX
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PPTX
Trends in pediatric nursing .pptx
AneetaSharma15
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Study Material and notes for Women Empowerment
ComputerScienceSACWC
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Trends in pediatric nursing .pptx
AneetaSharma15
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 

BCA Super Keyword.pptx

  • 2. Super Keyword in Java • The super keyword in Java is a reference variable which is used to refer immediate parent class object. • Whenever you create the object of subclass, an object of parent class is created implicitly which is referred by super reference variable.
  • 3. Usage of Java super Keyword 1. super can be used to refer immediate parent class instance variable. 2. super can be used to invoke immediate parent class method. 3. super() can be used to invoke immediate parent class constructor.
  • 4. 1. super is used to refer immediate parent class instance variable. • We can use super keyword to access the data member or field of parent class. • It is used if parent class and child class have same fields.
  • 5. Example class A { int a =10; } class B extends A { int a =20; void display() { System.out.println(a);//prints a of B class System.out.println(super.a);//prints a of A class } public static void main(String x[]) { B b1= new B(); b1.display(); } }
  • 7. 2. super can be used to invoke parent class method • The super keyword can also be used to invoke parent class method. • It should be used if subclass contains the same method as parent class. • In other words, it is used if method is overridden.
  • 8. Example class A { void display() { System.out.println("Class A"); } } class B extends A { void display() { System.out.println("Class B"); super.display(); } public static void main(String X[]) { B b1=new B(); b1. display(); } }
  • 10. 3. super() can be used to invoke immediate parent class constructor. • The super keyword can also be used to invoke the parent class constructor.
  • 11. Example class A { A() { System.out.println("Class A"); } } class B extends A { B() { super(); System.out.println("Class B"); } public static void main(String X[]) { B b1=new B(); } }