SlideShare a Scribd company logo
1 of 2
ARBA MINCH UNIVERSITY
INSTITUTE OF
TECHNOLOGY(AMIT)
FACULTY OF COMPUTER
&
SOFTWARE ENGINEERING
Object Oriented
Programming -OOP (Java)
SWE – Week 7 - 2021
METHOD OVERRIDING IN JAVA
What is method overriding?
Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method that
is already provided by one of its super-classes or parent classes. When a method in a subclass has the same
name, same parameters or signature, and same return type (or sub-type) as a method in its super-class, then the
method in the subclass is said to override the method in the super-class.
What is polymorphism?
Polymorphism is the ability of an object to take on many forms.
The most common use of polymorphism in OOP occurs when
A parent class reference is used to refer to a child class object.
Types of Polymorphism
Why overriding isrun time
polymorphism?
Because the methods get resolved at run time.
In simple words, when you execute a program,
the method of which class out of many will be
called, if they have overridden the method.
Using @Override
@Override annotation is used when we override a method in sub class.
Generally novice developers overlook this feature as it is not
mandatory to use this annotation while overriding the method.
Why we override a method in oop?
1) Large projects heavily depend on inheritance
2) Possible to change the method calling code at all occurrences of the project. it may break the whole project.
3) The code base refers to the same method with the same methods signature in different classes of the project.
class parent {
public void show() {
System.out.println ("parent");
}}
class child extends parent {
public void show() {
System.out.println("child");
}}
Public Static void main(String []args) {
parent p=new parent();
p.show();
child c=new child();
c.show();
parent p1=new child();
p1.show();
}} Output:
parent
child
child
class Father {
public void home() {
System.out.println("Father’s home");} public
void car() {
System.out.println("Father's Car");
} }
class Son extends Father{
@Override
public void car() {
System.out.println("Son's Car");
} }
public class TestOverriding {
public static void main(String[] args) {
Son s = new Son();
s.home(); s.car(); Out PUT:
Father’s home
Son’s Car
Group members
1) Eyob Mesfin NSR/957/12
2) Biniyam Belihu NSR/568/12
3) Ananiya Legese NSR/ 298/12

More Related Content

What's hot

What's hot (20)

C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
C# Interface | Interfaces In C# | C# Interfaces Explained | C# Tutorial For B...
 
C# question answers
C# question answersC# question answers
C# question answers
 
Chapter 9 Interface
Chapter 9 InterfaceChapter 9 Interface
Chapter 9 Interface
 
What is method overloading and overriding in java?
What is method overloading and overriding in java?What is method overloading and overriding in java?
What is method overloading and overriding in java?
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
OOP java
OOP javaOOP java
OOP java
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 
Xamarin: Namespace and Classes
Xamarin: Namespace and ClassesXamarin: Namespace and Classes
Xamarin: Namespace and Classes
 
Xamarin: C# Methods
Xamarin: C# MethodsXamarin: C# Methods
Xamarin: C# Methods
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Suga java training_with_footer
Suga java training_with_footerSuga java training_with_footer
Suga java training_with_footer
 
Object-Oriented Polymorphism Unleashed
Object-Oriented Polymorphism UnleashedObject-Oriented Polymorphism Unleashed
Object-Oriented Polymorphism Unleashed
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++
 
Java interface
Java interface Java interface
Java interface
 
Javapolymorphism
JavapolymorphismJavapolymorphism
Javapolymorphism
 
C# interview questions
C# interview questionsC# interview questions
C# interview questions
 
C# interview quesions
C# interview quesionsC# interview quesions
C# interview quesions
 
Mi0041 java and web design
Mi0041  java and web designMi0041  java and web design
Mi0041 java and web design
 
Java interface
Java interfaceJava interface
Java interface
 

Similar to Group 9(java method overriding).pdf

INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
Indu65
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
Arjun Shanka
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
Ganesh Samarthyam
 

Similar to Group 9(java method overriding).pdf (20)

Oops in PHP By Nyros Developer
Oops in PHP By Nyros DeveloperOops in PHP By Nyros Developer
Oops in PHP By Nyros Developer
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
 
Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_online
 
Inheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxInheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptx
 
06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt
 
INHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptxINHERITANCE IN JAVA.pptx
INHERITANCE IN JAVA.pptx
 
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptxINDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
INDUMATHY- UNIT 1 cs3391 oops introduction to oop and java.pptx
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
1669609053088_oops_final.pptx
1669609053088_oops_final.pptx1669609053088_oops_final.pptx
1669609053088_oops_final.pptx
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Unit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 POLYMORPHISM.pdfUnit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 POLYMORPHISM.pdf
 
Java 06
Java 06Java 06
Java 06
 
oopsinvb-191021101327.pdf
oopsinvb-191021101327.pdfoopsinvb-191021101327.pdf
oopsinvb-191021101327.pdf
 
Oops in vb
Oops in vbOops in vb
Oops in vb
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
What is method overloading and overriding in java?
What is method overloading and overriding in java?What is method overloading and overriding in java?
What is method overloading and overriding in java?
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 

Recently uploaded

QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Group 9(java method overriding).pdf

  • 1. ARBA MINCH UNIVERSITY INSTITUTE OF TECHNOLOGY(AMIT) FACULTY OF COMPUTER & SOFTWARE ENGINEERING Object Oriented Programming -OOP (Java) SWE – Week 7 - 2021 METHOD OVERRIDING IN JAVA What is method overriding? Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes. When a method in a subclass has the same name, same parameters or signature, and same return type (or sub-type) as a method in its super-class, then the method in the subclass is said to override the method in the super-class. What is polymorphism? Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when A parent class reference is used to refer to a child class object. Types of Polymorphism Why overriding isrun time polymorphism? Because the methods get resolved at run time. In simple words, when you execute a program, the method of which class out of many will be called, if they have overridden the method. Using @Override @Override annotation is used when we override a method in sub class. Generally novice developers overlook this feature as it is not mandatory to use this annotation while overriding the method.
  • 2. Why we override a method in oop? 1) Large projects heavily depend on inheritance 2) Possible to change the method calling code at all occurrences of the project. it may break the whole project. 3) The code base refers to the same method with the same methods signature in different classes of the project. class parent { public void show() { System.out.println ("parent"); }} class child extends parent { public void show() { System.out.println("child"); }} Public Static void main(String []args) { parent p=new parent(); p.show(); child c=new child(); c.show(); parent p1=new child(); p1.show(); }} Output: parent child child class Father { public void home() { System.out.println("Father’s home");} public void car() { System.out.println("Father's Car"); } } class Son extends Father{ @Override public void car() { System.out.println("Son's Car"); } } public class TestOverriding { public static void main(String[] args) { Son s = new Son(); s.home(); s.car(); Out PUT: Father’s home Son’s Car Group members 1) Eyob Mesfin NSR/957/12 2) Biniyam Belihu NSR/568/12 3) Ananiya Legese NSR/ 298/12