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

PPTX
2- Introduction to java II
PPTX
4- Inheritance, Aggregation, Encapsulation and Overloading
PPTX
#6- Arrays and Collections Framework
PPTX
Java interfaces
PPTX
OOP interview questions & answers.
PPTX
Structure of java program diff c- cpp and java
PPTX
java interface and packages
PPT
Data members and member functions
2- Introduction to java II
4- Inheritance, Aggregation, Encapsulation and Overloading
#6- Arrays and Collections Framework
Java interfaces
OOP interview questions & answers.
Structure of java program diff c- cpp and java
java interface and packages
Data members and member functions

What's hot (20)

PDF
Object Oriented Principles
PPTX
Interface in java ,multiple inheritance in java, interface implementation
PPTX
Abstract Class Presentation
PDF
Object oriented programming interview questions
PPTX
Java basics and java variables
PPTX
Introduction to C++ Programming
PPTX
Object as function argument , friend and static function by shahzad younas
PPT
Learn Java language fundamentals with Unit nexus
PPTX
Interfaces in java
PDF
Chapter 01 Introduction to Java by Tushar B Kute
PPTX
Classes objects in java
PPT
Java inheritance
PPTX
object oriented programming using c++
PDF
6 class and methods
PPTX
Multiple inheritance possible in Java
PPTX
Friend Function
PPT
Friends function and_classes
PPTX
Object oriented programming
PPTX
Object oriented programming
Object Oriented Principles
Interface in java ,multiple inheritance in java, interface implementation
Abstract Class Presentation
Object oriented programming interview questions
Java basics and java variables
Introduction to C++ Programming
Object as function argument , friend and static function by shahzad younas
Learn Java language fundamentals with Unit nexus
Interfaces in java
Chapter 01 Introduction to Java by Tushar B Kute
Classes objects in java
Java inheritance
object oriented programming using c++
6 class and methods
Multiple inheritance possible in Java
Friend Function
Friends function and_classes
Object oriented programming
Object oriented programming
Ad

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

PPTX
Polymorphism in java
DOC
116824015 java-j2 ee
PDF
Java/J2EE interview Qestions
DOC
Complete java&j2ee
DOCX
Core java by amit
DOCX
Corejavainterviewquestions.doc
TXT
Java interview
PPT
Super and final in java
DOC
Core java interview questions
PPTX
Java Access Specifier
PDF
L5
PDF
Non access modifiers
DOCX
Basic java important interview questions and answers to secure a job
PPTX
Java session2
PDF
polymorphismpresentation-160825122725.pdf
PPTX
When to use abstract class and methods in java
PPTX
Polymorphism presentation in java
PPT
03_A-OOPs_Interfaces.ppt
PPTX
Lecture 18
PDF
Java abstract Keyword.pdf
Polymorphism in java
116824015 java-j2 ee
Java/J2EE interview Qestions
Complete java&j2ee
Core java by amit
Corejavainterviewquestions.doc
Java interview
Super and final in java
Core java interview questions
Java Access Specifier
L5
Non access modifiers
Basic java important interview questions and answers to secure a job
Java session2
polymorphismpresentation-160825122725.pdf
When to use abstract class and methods in java
Polymorphism presentation in java
03_A-OOPs_Interfaces.ppt
Lecture 18
Java abstract Keyword.pdf
Ad

More from Ghadeer AlHasan (20)

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

Recently uploaded (20)

PPTX
Lesson notes of climatology university.
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Pre independence Education in Inndia.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Institutional Correction lecture only . . .
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
Lesson notes of climatology university.
2.FourierTransform-ShortQuestionswithAnswers.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
O5-L3 Freight Transport Ops (International) V1.pdf
Computing-Curriculum for Schools in Ghana
Insiders guide to clinical Medicine.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Pre independence Education in Inndia.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Anesthesia in Laparoscopic Surgery in India
VCE English Exam - Section C Student Revision Booklet
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Pharma ospi slides which help in ospi learning
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Sports Quiz easy sports quiz sports quiz
Institutional Correction lecture only . . .
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Supply Chain Operations Speaking Notes -ICLT Program
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
STATICS OF THE RIGID BODIES Hibbelers.pdf

5- Overriding and Abstraction In Java