SlideShare a Scribd company logo
P.1
Overriding and Abstraction
ghadeer-al-hasan ghadeerof@gamil.com
Java Overriding: P.2
 Overriding means to override the functionality of an existing method.
 A subclass implement a parent class method based on its requirement.
Java Overriding Cont. : P.3
Java Overriding Cont. : P.4
Java Overriding Cont. : P.5
Rules for method overriding:
 The argument list should be exactly the same as that of the overriding method.
 The return type should be the same of the return type declared in the original
override method in the superclass.
 If the supper class method is declared public then the overriding method in the
subclass cannot be either private or protected
 A method declared final cannot be overridden.
 A method declared static cannot be overridden.
 If a method cannot be inherited, then it cannot be overridden.
 A subclass in a different package can only override the non-final methods declared
public or protected.
P.6
Super keyword
super keyword : P.7
The super keyword in java is a reference variable that is used to refer
Immediate parent class object.
1) Super is used to refer immediate parent class instance variable.
super keyword Cont. : P.8
2) Super is used to invoked parent class constructor:
super() is added in each class constructor automatically by compiler.
super keyword Cont. : P.9
super keyword Cont. : P.10
3) super can be used to invoked parent class method:
super keyword Cont. : P.11
P.12
final keyword
final keyword : P.13
The final keyword is used to restrict the user, cam be used in many context:
 Variable
 Method
 class
1) final variable:
if you make any variable as final, you cannot change the value of final variable
final keyword Cont. : P.14
2)If you make any method as final , you cannot override it.
final keyword Cont. : P.15
2)If you make any method as final , you cannot override it, but is inherited.
final keyword Cont. : P.16
3)If you make any class as final, you cannot extend it.
final keyword Cont. : P.17
A final variable that is not initialized at the time of declaration can be
initialize only in constructor.
final keyword Cont. : P.18
A static final variable that is not initialized at the time of declaration can be
Initialized only in static block.
final keyword Cont. : P.19
If you declare any parameter as final, you cannot change the value of it.
You cannot declare constructor final because it is never inherited.
P.22
Abstraction
Abstraction P.21
• Is a process of hiding the implementation details and showing
Only functionality to the user.
• It shows only important things to the user and hides the internal details.
Abstract class:
• A class that is declared with abstract keyword, is know as abstract class
• It can have abstract and non abstract method.
• It needs to be extends and its method implemented,
it cannot be instantiated
Abstract method:
A method that is declared as abstract and does not have body.
Abstraction Example : P.22
P.23Abstraction Example :
P.24Abstraction Example :
P.25Notes :
Note:
 If there is any abstract method in a class, that class must be abstract.
 If you are extending any abstract class that have abstract method, you must either
provide the implementation of the method or make this class abstract.
P.26
Interfaces
P.27Interfaces:
 Is a mechanism to achieve fully abstraction.
 There can be only abstract methods .
 Used to achieve fully abstraction and multiple inheritance .
 Represents IS-A relationship.
 Cannot be instantiated just like abstract class.
P.S:
The java compiler adds public and abstract keywords before the interface method
And public, static and final keywords before data members.
P.28Classed and interfaces:
class
class
interface
class
interface
interface
extends extendsimplements
P.29Multiple inheritance:
interface
class
implements
interface interface
interface
extends
interface
P.30Interface Cont. :
P.31Interface Cont. :
P.32Instance initializer block:
 Is used to initialize the instance data member.
 It run each time when object of the class is created.
P.33Instance initializer block:
 The java compiler copies the code of instance initializer block in
every constructor.
compiler
P.34Instance initializer block Cont.:
P.35Instance initializer block:
The End
ghadeer-al-hasan ghadeerof@gamil.com

More Related Content

What's hot (20)

PDF
Object Oriented Principles
Sujit Majety
 
PPTX
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
PPTX
Abstract Class Presentation
tigerwarn
 
PDF
Object oriented programming interview questions
Keet Sugathadasa
 
PPTX
Java basics and java variables
Pushpendra Tyagi
 
PPTX
Introduction to C++ Programming
Preeti Kashyap
 
PPTX
Object as function argument , friend and static function by shahzad younas
Shahzad Younas
 
PPT
Learn Java language fundamentals with Unit nexus
Unit Nexus Pvt. Ltd.
 
PPTX
Interfaces in java
Abishek Purushothaman
 
PDF
Chapter 01 Introduction to Java by Tushar B Kute
Tushar B Kute
 
PPTX
Classes objects in java
Madishetty Prathibha
 
PPT
Java inheritance
Arati Gadgil
 
PPTX
object oriented programming using c++
fasalsial1fasalsial1
 
PDF
6 class and methods
Tuan Ngo
 
PPTX
Multiple inheritance possible in Java
Kurapati Vishwak
 
PPTX
Friend Function
Mehak Tawakley
 
PPT
Friends function and_classes
asadsardar
 
PPTX
Object oriented programming
Jun Shimizu
 
PPTX
Object oriented programming
umairrajpoot6
 
Object Oriented Principles
Sujit Majety
 
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
Abstract Class Presentation
tigerwarn
 
Object oriented programming interview questions
Keet Sugathadasa
 
Java basics and java variables
Pushpendra Tyagi
 
Introduction to C++ Programming
Preeti Kashyap
 
Object as function argument , friend and static function by shahzad younas
Shahzad Younas
 
Learn Java language fundamentals with Unit nexus
Unit Nexus Pvt. Ltd.
 
Interfaces in java
Abishek Purushothaman
 
Chapter 01 Introduction to Java by Tushar B Kute
Tushar B Kute
 
Classes objects in java
Madishetty Prathibha
 
Java inheritance
Arati Gadgil
 
object oriented programming using c++
fasalsial1fasalsial1
 
6 class and methods
Tuan Ngo
 
Multiple inheritance possible in Java
Kurapati Vishwak
 
Friend Function
Mehak Tawakley
 
Friends function and_classes
asadsardar
 
Object oriented programming
Jun Shimizu
 
Object oriented programming
umairrajpoot6
 

Similar to 5- Overriding and Abstraction In Java (20)

PPTX
Polymorphism in java
Elizabeth alexander
 
DOC
116824015 java-j2 ee
homeworkping9
 
PDF
Java/J2EE interview Qestions
Arun Vasanth
 
DOC
Complete java&j2ee
Shiva Cse
 
DOCX
Core java by amit
Thakur Amit Tomer
 
DOCX
Corejavainterviewquestions.doc
Joyce Thomas
 
TXT
Java interview
Mohammad Shahban
 
PPT
Super and final in java
anshu_atri
 
DOC
Core java interview questions
Vinay Kumar
 
PPTX
Java Access Specifier
DeeptiJava
 
PDF
L5
lksoo
 
PDF
Non access modifiers
Muthukumaran Subramanian
 
DOCX
Basic java important interview questions and answers to secure a job
Garuda Trainings
 
PPTX
Java session2
Rajeev Kumar
 
PDF
polymorphismpresentation-160825122725.pdf
BapanKar2
 
PPTX
When to use abstract class and methods in java
kritikumar16
 
PPTX
Polymorphism presentation in java
Ahsan Raja
 
PPT
03_A-OOPs_Interfaces.ppt
JyothiAmpally
 
PPTX
Lecture 18
talha ijaz
 
PDF
Java abstract Keyword.pdf
SudhanshiBakre1
 
Polymorphism in java
Elizabeth alexander
 
116824015 java-j2 ee
homeworkping9
 
Java/J2EE interview Qestions
Arun Vasanth
 
Complete java&j2ee
Shiva Cse
 
Core java by amit
Thakur Amit Tomer
 
Corejavainterviewquestions.doc
Joyce Thomas
 
Java interview
Mohammad Shahban
 
Super and final in java
anshu_atri
 
Core java interview questions
Vinay Kumar
 
Java Access Specifier
DeeptiJava
 
L5
lksoo
 
Non access modifiers
Muthukumaran Subramanian
 
Basic java important interview questions and answers to secure a job
Garuda Trainings
 
Java session2
Rajeev Kumar
 
polymorphismpresentation-160825122725.pdf
BapanKar2
 
When to use abstract class and methods in java
kritikumar16
 
Polymorphism presentation in java
Ahsan Raja
 
03_A-OOPs_Interfaces.ppt
JyothiAmpally
 
Lecture 18
talha ijaz
 
Java abstract Keyword.pdf
SudhanshiBakre1
 
Ad

More from Ghadeer AlHasan (20)

PPTX
[C++ Tutorial ] #9 Classes
Ghadeer AlHasan
 
PPTX
[C++ Tutorial] #8 Files
Ghadeer AlHasan
 
PPTX
[C++ Tutorial] #7- Linked List
Ghadeer AlHasan
 
PPTX
[Java] #8 String and Inner Class
Ghadeer AlHasan
 
PPTX
[C++ Tutorial] #6- Pointers
Ghadeer AlHasan
 
PPTX
[Java] #7 - Input & Output Stream
Ghadeer AlHasan
 
PPTX
[C++] #5 - Structures
Ghadeer AlHasan
 
PPTX
3- Operators in Java
Ghadeer AlHasan
 
PPTX
1- Introduction to java
Ghadeer AlHasan
 
PPTX
0- Overview
Ghadeer AlHasan
 
PPTX
4- Arrays
Ghadeer AlHasan
 
PPTX
3- Functions
Ghadeer AlHasan
 
PPTX
2- Control Structures
Ghadeer AlHasan
 
PPTX
1- Languages Basics
Ghadeer AlHasan
 
PPTX
#8 (Java Message Service)
Ghadeer AlHasan
 
PPTX
#7 (Java Message Service)
Ghadeer AlHasan
 
PPTX
#6 (RESTtful Web Wervices)
Ghadeer AlHasan
 
PPTX
#5 (Remote Method Invocation)
Ghadeer AlHasan
 
PPTX
#4 (Remote Method Invocation)
Ghadeer AlHasan
 
PPTX
#3 (Multi Threads With TCP)
Ghadeer AlHasan
 
[C++ Tutorial ] #9 Classes
Ghadeer AlHasan
 
[C++ Tutorial] #8 Files
Ghadeer AlHasan
 
[C++ Tutorial] #7- Linked List
Ghadeer AlHasan
 
[Java] #8 String and Inner Class
Ghadeer AlHasan
 
[C++ Tutorial] #6- Pointers
Ghadeer AlHasan
 
[Java] #7 - Input & Output Stream
Ghadeer AlHasan
 
[C++] #5 - Structures
Ghadeer AlHasan
 
3- Operators in Java
Ghadeer AlHasan
 
1- Introduction to java
Ghadeer AlHasan
 
0- Overview
Ghadeer AlHasan
 
4- Arrays
Ghadeer AlHasan
 
3- Functions
Ghadeer AlHasan
 
2- Control Structures
Ghadeer AlHasan
 
1- Languages Basics
Ghadeer AlHasan
 
#8 (Java Message Service)
Ghadeer AlHasan
 
#7 (Java Message Service)
Ghadeer AlHasan
 
#6 (RESTtful Web Wervices)
Ghadeer AlHasan
 
#5 (Remote Method Invocation)
Ghadeer AlHasan
 
#4 (Remote Method Invocation)
Ghadeer AlHasan
 
#3 (Multi Threads With TCP)
Ghadeer AlHasan
 
Ad

Recently uploaded (20)

PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
community health nursing question paper 2.pdf
Prince kumar
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 

5- Overriding and Abstraction In Java