SlideShare a Scribd company logo
1 of 8
(SCJP/OCJP) (SCWCD/OCWCD)
Jayanthi Mani M.S.
Introduction
Overloading in Java
Why learn Overloading?
 ‘Overloading’ is one of the crucial and fundamental
concepts of core Java
 The concept of ‘Overloading’ promotes clean Java coding
Example of Overloading
public int operator(int a, int b){
return a+b;}
public float operator(float a, float b){
return a+b;
}
Note the different
argument lists – first
method takes integers
as its argument
The second method
takes floating type
variables as its
argument
Facts of Overloading
 Only methods in Java can be overloaded
 Methods can be overloaded in the same class or sub-class
 Each overloaded method is considered to be a separate
method
Rules for Overloading
 In order for the method to be considered overloaded, the
argument list MUST be different
 Just changing the return type and access modifier of a
method is not enough to make it overloaded
Invoking Overloaded methods
As an example, when the compiler sees
operator(5, 3);
it calls this method
public int operator(int a, int b){
return a+b;
}
Overloaded methods can
 have a different return type
 have a different access
modifier(can be more restrictive)
 throw new or broader
exceptions BUT MUST
differ in the argument list
Summary
Overloading

More Related Content

Similar to Overloading

Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_onlinenishajj
 
Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Geekster
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingKumar
 
NIKUL SURANI
NIKUL SURANINIKUL SURANI
NIKUL SURANINikul4470
 
Operator overloaing
Operator overloaingOperator overloaing
Operator overloaingzindadili
 
java Method Overloading
java Method Overloadingjava Method Overloading
java Method Overloadingomkar bhagat
 
BCA Oveloading and Overriding (2).pptx
BCA Oveloading and Overriding (2).pptxBCA Oveloading and Overriding (2).pptx
BCA Oveloading and Overriding (2).pptxSarthakSrivastava70
 
U2 JAVA.pptx
U2 JAVA.pptxU2 JAVA.pptx
U2 JAVA.pptxmadan r
 

Similar to Overloading (10)

Learn java lessons_online
Learn java lessons_onlineLearn java lessons_online
Learn java lessons_online
 
11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf
 
Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
NIKUL SURANI
NIKUL SURANINIKUL SURANI
NIKUL SURANI
 
Operator overloaing
Operator overloaingOperator overloaing
Operator overloaing
 
java Method Overloading
java Method Overloadingjava Method Overloading
java Method Overloading
 
BCA Oveloading and Overriding (2).pptx
BCA Oveloading and Overriding (2).pptxBCA Oveloading and Overriding (2).pptx
BCA Oveloading and Overriding (2).pptx
 
U2 JAVA.pptx
U2 JAVA.pptxU2 JAVA.pptx
U2 JAVA.pptx
 

Recently uploaded

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

Overloading

  • 1. (SCJP/OCJP) (SCWCD/OCWCD) Jayanthi Mani M.S. Introduction Overloading in Java
  • 2. Why learn Overloading?  ‘Overloading’ is one of the crucial and fundamental concepts of core Java  The concept of ‘Overloading’ promotes clean Java coding
  • 3. Example of Overloading public int operator(int a, int b){ return a+b;} public float operator(float a, float b){ return a+b; } Note the different argument lists – first method takes integers as its argument The second method takes floating type variables as its argument
  • 4. Facts of Overloading  Only methods in Java can be overloaded  Methods can be overloaded in the same class or sub-class  Each overloaded method is considered to be a separate method
  • 5. Rules for Overloading  In order for the method to be considered overloaded, the argument list MUST be different  Just changing the return type and access modifier of a method is not enough to make it overloaded
  • 6. Invoking Overloaded methods As an example, when the compiler sees operator(5, 3); it calls this method public int operator(int a, int b){ return a+b; }
  • 7. Overloaded methods can  have a different return type  have a different access modifier(can be more restrictive)  throw new or broader exceptions BUT MUST differ in the argument list Summary

Editor's Notes

  1. Hello everyone…I am Jayanthi and today’s video will focus on Overloading in Java.
  2. Next, we will see what is meant by overloading. Overloading as the name suggests is giving the same to different methods but achieving different functionality by providing different argument lists, return type or access modifier. Here we see two methods which are overloaded – they are Public int area(int a, int b) and Public int area(int a, int b, int c) Both of these methods are used to find the area – but one takes two integers as argument and the other takes three integers as its argument. It must be noted that unlike other programming languages Java only supports method overloading and not operator overloading
  3. Next, we will see what is meant by overloading. Overloading as the name suggests is giving the same to different methods but achieving different functionality by providing different argument lists, return type or access modifier. Here we see two methods which are overloaded – they are Public int area(int a, int b) and Public int area(int a, int b, int c) Both of these methods are used to find the area – but one takes two integers as argument and the other takes three integers as its argument. It must be noted that unlike other programming languages Java only supports method overloading and not operator overloading
  4. Next, we present some rules for overloading. This will be help us in creating effective overloaded methods in our programs. The most important rule is that a method is considered overloaded only if the argument list is different(both number and type of arguments). For example, the area method showed one method having two integers as arguments while the other method showed three integers as arguments. Changing the return type and access modifier do not make a method overloaded. It is also important to note that each overloaded method is a separate method.
  5. Next we deal with the question of how overloaded methods are invoked. How does the compiler know which method to call when there are two overloaded methods with the same name? The compiler will decide this based on the argument lists. If the method with integer argument is invoked, then the compiler calls the method with integer arguments. Similarly, if the method with floating arguments is invoked, then the compiler calls the appropriate method with floating type arguments. We see this in our example, when the compiler sees Operator(3,5) in our code, then the compiler immediately calls the operator method having two integers as its argument. When the compiler sees operator(1.2,2.3), it immediately calls the operator method having two floating point variables as its argument. We will now move onto a demonstration of this concept.