SlideShare a Scribd company logo
2
Most read
3
Most read
8
Most read
Introduction to Method Overloading
& Method Overriding in Java
Harshal Misalkar
2
Introduction
Polymorphism
poly=many
morphism=forms
i.e one interface having many methods.
Polymorphism simply means many forms.
It can be defined as one thing performing
different forms.
3
Introduction
4
Following concepts demonstrate different types of polymorphism
1) Method Overloading
2) Method Overriding
If a class have multiple methods by same name
but different parameters, it is known as Method
Overloading.
If we have to perform only one operation, having
same name of the methods increases the
readability of the program.
5
Advantage of method overloading
Method overloading increases the readability of
the program.
Different ways to overload the method
By changing number of arguments.
By changing the data type.
.
6
In this example, we have created two overloaded methods, first sum method performs
addition of two numbers and second sum method performs addition of three numbers.
class Morning
{
public void sum(int a, int b)
{
System.out.println(a+b);
}
public void sum(int a,int b,int c)
{
System.out.println(a+b+c);
}
public static void main(String args[])
{
Morning h=new Morning();
h.sum(10,20);
h.sum(10,20,30);
System.out.println("Hello Java");
}
}
7
In this example, we have created two overloaded methods that differs in data type. The
first sum method receives two integer arguments and second sum method receives two
double arguments.
class hello
{
public void sum(int a, int b)
{
System.out.println(a+b);
}
public void sum(double a, double b)
{
System.out.println(a+b);
}
public static void main(String args[])
{
hello h=new hello();
h.sum(10,20);
h.sum(10.20, 30.50);
System.out.println("Hello Java");
}
}
8
Method Overriding in Java
If subclass (child class) has the same method as declared in the
parent class, it is known as method overriding in java.
In other words, If subclass provides the specific
implementation of the method that has been provided by one of
its parent class, it is known as method overriding.
Usage of Java Method Overriding
Method overriding is used to provide specific implementation
of a method that is already provided by its super class.
Method overriding is used for runtime polymorphism
Rules for Java Method Overriding
method must have same name as in the parent class
method must have same parameter as in the parent class.
9
Example of method overriding
In this example, we have defined the display method in the subclass as defined in the parent class but it has some
specific implementation.
class Parent
{
int a=50;
public void display()
{
System.out.println("Display method of Parent class");
}
}
class Child extends Parent
{
int b=100;
public void display()
{
System.out.println("Display method of Child class");
}
}
class MethodOverriding
{
public static void main(String args[])
{
Child d=new Child();
d.display();
}
}
9
Example of method overriding
In this example, we have defined the display method in the subclass as defined in the parent class but it has some
specific implementation.
class Parent
{
int a=50;
public void display()
{
System.out.println("Display method of Parent class");
}
}
class Child extends Parent
{
int b=100;
public void display()
{
System.out.println("Display method of Child class");
}
}
class MethodOverriding
{
public static void main(String args[])
{
Child d=new Child();
d.display();
}
}

More Related Content

PPTX
Event management ppt.
PPTX
Method overloading
PDF
Method Overloading In Java
PPTX
Introduction to java
PPTX
ARTIFICIAL INTELLIGENCE IN DAY TO DAY LIFE
PPTX
Beta and gamma function
PDF
Concurrent/ parallel programming
PPTX
Java exception handling
Event management ppt.
Method overloading
Method Overloading In Java
Introduction to java
ARTIFICIAL INTELLIGENCE IN DAY TO DAY LIFE
Beta and gamma function
Concurrent/ parallel programming
Java exception handling

What's hot (20)

PPTX
Method Overloading in Java
PPT
Abstract class in java
PPTX
Constructor in java
PPT
Java interfaces
PPTX
PPTX
This keyword in java
PPTX
Java abstract class & abstract methods
PPS
Java Exception handling
PPTX
Applets in java
PPTX
Pure virtual function and abstract class
PPTX
constructors in java ppt
PDF
Oops concepts || Object Oriented Programming Concepts in Java
PPTX
Access specifiers(modifiers) in java
PPTX
class and objects
PDF
Polymorphism in Java
PPS
Interface
PPTX
Exception Handling in Java
PPTX
java interface and packages
ODP
OOP java
Method Overloading in Java
Abstract class in java
Constructor in java
Java interfaces
This keyword in java
Java abstract class & abstract methods
Java Exception handling
Applets in java
Pure virtual function and abstract class
constructors in java ppt
Oops concepts || Object Oriented Programming Concepts in Java
Access specifiers(modifiers) in java
class and objects
Polymorphism in Java
Interface
Exception Handling in Java
java interface and packages
OOP java
Ad

Viewers also liked (20)

PPT
Polymorphism in java, method overloading and method overriding
PPT
Method overriding
PPT
Method overloading
PPTX
Overloading in java
DOC
Danelle Williams Resume_Healthcare Administration (2)
PPTX
Inheritance question class 12th
PPTX
2CPP11 - Method Overloading
PDF
itft-Inheritance in java
PDF
OOP Inheritance
PDF
Inheritance and Method Overriding
PPTX
Multiple inheritance possible in Java
PPT
Inheritance, polymorphisam, abstract classes and composition)
PPT
Oop Presentation
PDF
Chapter2 Encapsulation (Java)
PPT
Java Arrays
PPTX
Flavor encapsulation assignment
PPTX
Object Orinted Programing(OOP) concepts \
DOC
Server,System Administration Resume
PPTX
Arrays in Java
Polymorphism in java, method overloading and method overriding
Method overriding
Method overloading
Overloading in java
Danelle Williams Resume_Healthcare Administration (2)
Inheritance question class 12th
2CPP11 - Method Overloading
itft-Inheritance in java
OOP Inheritance
Inheritance and Method Overriding
Multiple inheritance possible in Java
Inheritance, polymorphisam, abstract classes and composition)
Oop Presentation
Chapter2 Encapsulation (Java)
Java Arrays
Flavor encapsulation assignment
Object Orinted Programing(OOP) concepts \
Server,System Administration Resume
Arrays in Java
Ad

Similar to Introduction to method overloading & method overriding in java hdm (20)

PPTX
polymorphism method overloading and overriding .pptx
PDF
Learn java lessons_online
PDF
Java Polymorphism: Types And Examples (Geekster)
PPTX
Oop concepts classes Method Overriding.pptx
PPTX
Polymorphism in java
PDF
Unit 2 Part 1 POLYMORPHISM.pdf
PPTX
Inheritance Interface and Packags in java programming.pptx
PPTX
Overloading and overriding in vb.net
PPTX
Java inheritance
PDF
Method overloading and method overriding
PPTX
Lecture5_Method_overloading_Final power point presentation
PPTX
Lecture4_Method_overloading power point presentaion
PPTX
Lecture_5_Method_overloading_Final.pptx in Java
PPTX
Unit No 3 Inheritance annd Polymorphism.pptx
PPTX
Lecture 6 inheritance
PPTX
Polymorphism.pptx
PPTX
Inheritance,single,multiple.access rulepptx
PPTX
Inheritance Slides
PPTX
Object+oriented+programming+in+java
PPTX
OOP- PolymorphismFinal12injavait101.pptx
polymorphism method overloading and overriding .pptx
Learn java lessons_online
Java Polymorphism: Types And Examples (Geekster)
Oop concepts classes Method Overriding.pptx
Polymorphism in java
Unit 2 Part 1 POLYMORPHISM.pdf
Inheritance Interface and Packags in java programming.pptx
Overloading and overriding in vb.net
Java inheritance
Method overloading and method overriding
Lecture5_Method_overloading_Final power point presentation
Lecture4_Method_overloading power point presentaion
Lecture_5_Method_overloading_Final.pptx in Java
Unit No 3 Inheritance annd Polymorphism.pptx
Lecture 6 inheritance
Polymorphism.pptx
Inheritance,single,multiple.access rulepptx
Inheritance Slides
Object+oriented+programming+in+java
OOP- PolymorphismFinal12injavait101.pptx

Recently uploaded (20)

PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
DOCX
573137875-Attendance-Management-System-original
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
additive manufacturing of ss316l using mig welding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Current and future trends in Computer Vision.pptx
PDF
composite construction of structures.pdf
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
Mechanical Engineering MATERIALS Selection
PPT
Project quality management in manufacturing
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Sustainable Sites - Green Building Construction
PDF
R24 SURVEYING LAB MANUAL for civil enggi
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
573137875-Attendance-Management-System-original
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
additive manufacturing of ss316l using mig welding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Current and future trends in Computer Vision.pptx
composite construction of structures.pdf
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
UNIT-1 - COAL BASED THERMAL POWER PLANTS
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Mechanical Engineering MATERIALS Selection
Project quality management in manufacturing
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
OOP with Java - Java Introduction (Basics)
Sustainable Sites - Green Building Construction
R24 SURVEYING LAB MANUAL for civil enggi

Introduction to method overloading & method overriding in java hdm

  • 1. Introduction to Method Overloading & Method Overriding in Java Harshal Misalkar
  • 2. 2 Introduction Polymorphism poly=many morphism=forms i.e one interface having many methods. Polymorphism simply means many forms. It can be defined as one thing performing different forms.
  • 4. 4 Following concepts demonstrate different types of polymorphism 1) Method Overloading 2) Method Overriding If a class have multiple methods by same name but different parameters, it is known as Method Overloading. If we have to perform only one operation, having same name of the methods increases the readability of the program.
  • 5. 5 Advantage of method overloading Method overloading increases the readability of the program. Different ways to overload the method By changing number of arguments. By changing the data type. .
  • 6. 6 In this example, we have created two overloaded methods, first sum method performs addition of two numbers and second sum method performs addition of three numbers. class Morning { public void sum(int a, int b) { System.out.println(a+b); } public void sum(int a,int b,int c) { System.out.println(a+b+c); } public static void main(String args[]) { Morning h=new Morning(); h.sum(10,20); h.sum(10,20,30); System.out.println("Hello Java"); } }
  • 7. 7 In this example, we have created two overloaded methods that differs in data type. The first sum method receives two integer arguments and second sum method receives two double arguments. class hello { public void sum(int a, int b) { System.out.println(a+b); } public void sum(double a, double b) { System.out.println(a+b); } public static void main(String args[]) { hello h=new hello(); h.sum(10,20); h.sum(10.20, 30.50); System.out.println("Hello Java"); } }
  • 8. 8 Method Overriding in Java If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in java. In other words, If subclass provides the specific implementation of the method that has been provided by one of its parent class, it is known as method overriding. Usage of Java Method Overriding Method overriding is used to provide specific implementation of a method that is already provided by its super class. Method overriding is used for runtime polymorphism Rules for Java Method Overriding method must have same name as in the parent class method must have same parameter as in the parent class.
  • 9. 9 Example of method overriding In this example, we have defined the display method in the subclass as defined in the parent class but it has some specific implementation. class Parent { int a=50; public void display() { System.out.println("Display method of Parent class"); } } class Child extends Parent { int b=100; public void display() { System.out.println("Display method of Child class"); } } class MethodOverriding { public static void main(String args[]) { Child d=new Child(); d.display(); } }
  • 10. 9 Example of method overriding In this example, we have defined the display method in the subclass as defined in the parent class but it has some specific implementation. class Parent { int a=50; public void display() { System.out.println("Display method of Parent class"); } } class Child extends Parent { int b=100; public void display() { System.out.println("Display method of Child class"); } } class MethodOverriding { public static void main(String args[]) { Child d=new Child(); d.display(); } }

Editor's Notes

  • #2: First Class: Introduction, Prerequisites, Advices, Syllabus Lab 1: Create a Java Project, Compile, and Run. Show syntax errors Print program Capture screen shots, and save it in Word, and print it. Homework One: Check in the class randomly.