SlideShare a Scribd company logo
1 of 13
Download to read offline
METHOD OVERLOADING IN JAVA
BY: CHARTHA GAGLANI
INTRODUCTION
• If a class of a Java program has a plural number of methods, and all of
them have the same name but different parameters (with a change in type
or number of arguments), and programmers can use them to perform a
similar form of functions, then it is known as method overloading.
• If programmers wants to perform one operation, having the same name,
the method increases the readability of the program.
• Method Overloading is applied in a program when objects are required to
perform similar tasks but different input parameters. Every time an object
calls a method, Java matches up to the method name first and then the
number and type of parameters to decide what definitions to execute.
• This process of assigning multiple tasks to the same method is known
as Polymorphism. There are different ways to overload a method in Java.
They are:
• Based on the number of parameters: In this case, the entire overloading
concept depends on the number of parameters that are placed within the
parenthesis of the method.
• Based on the data type of the parameter: With the arrangement of data type,
within the parameter, overloading of the method can take place.
• Based on the sequence of data types in parameters: The method
overloading also depends on the ordering of data types of parameters
within the method.
SYNTAX
PROGRAM FOR METHOD OVERLOADING
OUTPUT:
Why method overloading in java is not possible by
changing the return type of method is changed?
• In Java, method overloading is not possible by changing the return type of
the method because there may arise some ambiguity. Let's see how
ambiguity may occur:
• The above program will generate a compile-time error.
• Here, Java cannot determine which sum() method to call and hence creates an error if you want
to overload like this by using the return type. Overloading methods offer no specific benefit to the
JVM, but it is useful to the program to have several ways do the same things but with different
parameters.
OTHER EXAMPLES
PROGRAM TO DEMONSTRATE METHOD OVERLOADING BASED
ON THE SEQUENCE OF DATA TYPE IN THE PARAMETERS
ADVANTAGES
• It is used to perform a task efficiently with smartness in programming.
• It increases the readability of the program.
• The Method overloading allows methods that perform proximately related
functions to be accessed using a common name with slight variation in
argument number or types.
• They can also be implemented on constructors allowing different ways to
initialize objects of a class.
DISADVANTAGES
• Not very easy for the beginner to opt this programming technique and go
with it.
• It requires more significant effort spent on designing the architecture (i.e.,
the arguments' type and number) to up front, at least if programmers' want
to avoid massive code from rewriting.
THANK YOU

More Related Content

What's hot (20)

Interface in java
Interface in javaInterface in java
Interface in java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
OOP java
OOP javaOOP java
OOP java
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Abstraction in java
Abstraction in javaAbstraction in java
Abstraction in java
 
Java threads
Java threadsJava threads
Java threads
 
Java constructors
Java constructorsJava constructors
Java constructors
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 

Similar to Method Overloading In Java

Unit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 POLYMORPHISM.pdfUnit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 POLYMORPHISM.pdfArpana Awasthi
 
overloading
overloadingoverloading
overloadingcpsivaku
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method OverloadingMichael Heron
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1Sherihan Anver
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptxRaazIndia
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxKunalYadav65140
 
The Java Learning Kit Chapter 5 – Methods and Modular.docx
The Java Learning Kit Chapter 5 – Methods and Modular.docxThe Java Learning Kit Chapter 5 – Methods and Modular.docx
The Java Learning Kit Chapter 5 – Methods and Modular.docxarnoldmeredith47041
 
Lecture5_Method_overloading_Final power point presentation
Lecture5_Method_overloading_Final power point presentationLecture5_Method_overloading_Final power point presentation
Lecture5_Method_overloading_Final power point presentationbhargavi804095
 
Lecture4_Method_overloading power point presentaion
Lecture4_Method_overloading power point presentaionLecture4_Method_overloading power point presentaion
Lecture4_Method_overloading power point presentaionbhargavi804095
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigmsAshok Raj
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programmingAmar Jukuntla
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class featuresRakesh Madugula
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfnofakeNews
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#Muhammad Younis
 

Similar to Method Overloading In Java (20)

Unit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 POLYMORPHISM.pdfUnit 2 Part 1 POLYMORPHISM.pdf
Unit 2 Part 1 POLYMORPHISM.pdf
 
overloading
overloadingoverloading
overloading
 
Java basics training 1
Java basics training 1Java basics training 1
Java basics training 1
 
2CPP11 - Method Overloading
2CPP11 - Method Overloading2CPP11 - Method Overloading
2CPP11 - Method Overloading
 
what is method overloading?
what is method overloading?what is method overloading?
what is method overloading?
 
UNIT1-JAVA.pptx
UNIT1-JAVA.pptxUNIT1-JAVA.pptx
UNIT1-JAVA.pptx
 
Java Jive 002.pptx
Java Jive 002.pptxJava Jive 002.pptx
Java Jive 002.pptx
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
The Java Learning Kit Chapter 5 – Methods and Modular.docx
The Java Learning Kit Chapter 5 – Methods and Modular.docxThe Java Learning Kit Chapter 5 – Methods and Modular.docx
The Java Learning Kit Chapter 5 – Methods and Modular.docx
 
Lecture5_Method_overloading_Final power point presentation
Lecture5_Method_overloading_Final power point presentationLecture5_Method_overloading_Final power point presentation
Lecture5_Method_overloading_Final power point presentation
 
Lecture4_Method_overloading power point presentaion
Lecture4_Method_overloading power point presentaionLecture4_Method_overloading power point presentaion
Lecture4_Method_overloading power point presentaion
 
OOPJ.pptx
OOPJ.pptxOOPJ.pptx
OOPJ.pptx
 
Programming language paradigms
Programming language paradigmsProgramming language paradigms
Programming language paradigms
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 

More from CharthaGaglani

Macromolecular interaction
Macromolecular interactionMacromolecular interaction
Macromolecular interactionCharthaGaglani
 
Characteristics and Advantages of Database Management System
Characteristics and Advantages of Database Management SystemCharacteristics and Advantages of Database Management System
Characteristics and Advantages of Database Management SystemCharthaGaglani
 
Cosmid Vectors, YAC and BAC Expression Vectors
Cosmid Vectors, YAC and BAC Expression VectorsCosmid Vectors, YAC and BAC Expression Vectors
Cosmid Vectors, YAC and BAC Expression VectorsCharthaGaglani
 
Transplantation immunology
Transplantation immunologyTransplantation immunology
Transplantation immunologyCharthaGaglani
 
Sex linked inheritance
Sex linked inheritanceSex linked inheritance
Sex linked inheritanceCharthaGaglani
 
Phylogenetics an overview
Phylogenetics an overviewPhylogenetics an overview
Phylogenetics an overviewCharthaGaglani
 
Saccharomyces cerevisiae
Saccharomyces cerevisiaeSaccharomyces cerevisiae
Saccharomyces cerevisiaeCharthaGaglani
 
Applications of computer
Applications of computerApplications of computer
Applications of computerCharthaGaglani
 

More from CharthaGaglani (13)

Reference Manager.pdf
Reference Manager.pdfReference Manager.pdf
Reference Manager.pdf
 
Macromolecular interaction
Macromolecular interactionMacromolecular interaction
Macromolecular interaction
 
Characteristics and Advantages of Database Management System
Characteristics and Advantages of Database Management SystemCharacteristics and Advantages of Database Management System
Characteristics and Advantages of Database Management System
 
Cosmid Vectors, YAC and BAC Expression Vectors
Cosmid Vectors, YAC and BAC Expression VectorsCosmid Vectors, YAC and BAC Expression Vectors
Cosmid Vectors, YAC and BAC Expression Vectors
 
Bayesian inference
Bayesian inferenceBayesian inference
Bayesian inference
 
Antiviral agents
Antiviral agentsAntiviral agents
Antiviral agents
 
Transplantation immunology
Transplantation immunologyTransplantation immunology
Transplantation immunology
 
Sex linked inheritance
Sex linked inheritanceSex linked inheritance
Sex linked inheritance
 
Plastids presentation
Plastids presentationPlastids presentation
Plastids presentation
 
Phylogenetics an overview
Phylogenetics an overviewPhylogenetics an overview
Phylogenetics an overview
 
Saccharomyces cerevisiae
Saccharomyces cerevisiaeSaccharomyces cerevisiae
Saccharomyces cerevisiae
 
Applications of computer
Applications of computerApplications of computer
Applications of computer
 
Amino acids
Amino acidsAmino acids
Amino acids
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 

Method Overloading In Java

  • 1. METHOD OVERLOADING IN JAVA BY: CHARTHA GAGLANI
  • 2. INTRODUCTION • If a class of a Java program has a plural number of methods, and all of them have the same name but different parameters (with a change in type or number of arguments), and programmers can use them to perform a similar form of functions, then it is known as method overloading. • If programmers wants to perform one operation, having the same name, the method increases the readability of the program. • Method Overloading is applied in a program when objects are required to perform similar tasks but different input parameters. Every time an object calls a method, Java matches up to the method name first and then the number and type of parameters to decide what definitions to execute.
  • 3. • This process of assigning multiple tasks to the same method is known as Polymorphism. There are different ways to overload a method in Java. They are: • Based on the number of parameters: In this case, the entire overloading concept depends on the number of parameters that are placed within the parenthesis of the method. • Based on the data type of the parameter: With the arrangement of data type, within the parameter, overloading of the method can take place. • Based on the sequence of data types in parameters: The method overloading also depends on the ordering of data types of parameters within the method.
  • 5. PROGRAM FOR METHOD OVERLOADING OUTPUT:
  • 6. Why method overloading in java is not possible by changing the return type of method is changed? • In Java, method overloading is not possible by changing the return type of the method because there may arise some ambiguity. Let's see how ambiguity may occur:
  • 7. • The above program will generate a compile-time error. • Here, Java cannot determine which sum() method to call and hence creates an error if you want to overload like this by using the return type. Overloading methods offer no specific benefit to the JVM, but it is useful to the program to have several ways do the same things but with different parameters.
  • 9.
  • 10. PROGRAM TO DEMONSTRATE METHOD OVERLOADING BASED ON THE SEQUENCE OF DATA TYPE IN THE PARAMETERS
  • 11. ADVANTAGES • It is used to perform a task efficiently with smartness in programming. • It increases the readability of the program. • The Method overloading allows methods that perform proximately related functions to be accessed using a common name with slight variation in argument number or types. • They can also be implemented on constructors allowing different ways to initialize objects of a class.
  • 12. DISADVANTAGES • Not very easy for the beginner to opt this programming technique and go with it. • It requires more significant effort spent on designing the architecture (i.e., the arguments' type and number) to up front, at least if programmers' want to avoid massive code from rewriting.