SlideShare ist ein Scribd-Unternehmen logo
1 von 18
METHOD OVERLOADING

           vishnukishorbabu@gmail.com
                        @Vishnu_Kishor
METHOD
• A collection of statements that are grouped
  together to perform an operation
• A method has the following syntax
    modifier return_Value_Type Method_Name(list
    of parameters)
    {      // Method body; }
• A method definition consists of a method
  header and a method body
PARTS OF METHOD
1. Modifiers:
  – Optional
  – Tells the compiler how to call the method.
  – Defines the access type of the method.
2. Return Types
  – The data type of the value the method returns.
  – the return type is the keyword void when no
    value is returned
• Method Name
  – The actual name of the method.
  – Method name and the parameter list together
    constitute the method signature.

• Parameters
  – Act as a placeholder.
  – When a method is invoked, a value is passed to
    parameter.
  – This value is referred to as actual parameter or
    argument.
  – The parameter list refers to the type, order, and
    number of the parameters of a method.
  – Parameters are optional; that is,
• Method Body
  – The method body contains a collection of
    statements that define what the method does.
METHOD OVERLOADING
• A concept in Java which allows programmer to
  declare method with same name but different
  behavior
• Method with same name co-exists in same class
  but they must have different method signature
• Resolved using static binding in Java at compile
  time
• When you overload a method in Java its method
  signature gets changed
How to overload a method in Java
• If you have two methods with same name in
  one Java class with different method signature
  than its called overloaded method in Java
• Generally overloaded method in Java has
  different set of arguments to perform
  something based on different number of input
• Binding of overloading method occurs during
  compile time and overloaded calls resolved
  using static binding.
• To overload a Java method just changes its
  signature.
• To change signature, either change number of
  argument, type of argument or order of
  argument
• Since return type is not part of method
  signature changing return type will result in
  duplicate method and you will get compile
  time error in Java
Static and Dynamic Binding
• Binding-process used to link which method or
  variable to be called as result of their
  reference in code
• Two types of binding
  – Static Binding, and
  – Dynamic Binding.
• Static binding in Java occurs during Compile
  time while Dynamic binding occurs during Runtime.
• private, final and static methods and variables uses
  static binding and bonded by compiler while virtual
  methods are bonded during runtime based upon
  runtime object.
• Static binding uses class information for binding
  while Dynamic binding uses Object to resolve
  binding.
• Overloaded method are bonded using static binding
  while overridden methods are bonded during
  compile time.
   – Method override -A method in subclass has the same name & type
     signature as a method in its superclass.
Example
public class MethodOverLoading {
// Method 1
  public static int Addition(int a, int b) {
  System.out.println(“Method 1 is called”);
  return a + b;
   }
// Method 2
  public static int Addition(int a, int b, int c) {
  System.out.println(“Method 2 is called”);
  return a + b + c;
  }
  }
public static void main(String[] args) {
int Answer1 = Addition(5, 6); // In this case
            Method 1 will be called
System.out.println(“Answer 1 = ” + Answer1);
System.out.println(“----------------------------”);
int Answer2 = Addition(5, 6, 7); // In this case
                  Method 2 will be called
System.out.println(“Answer 2 = ” + Answer2);
}
Output of the code
 Method 1 is called
 Answer 1 = 11
 ----------------------------
 Method 2 is called
 Answer 2 = 18
Thank you
Disclaimer: This presentation is prepared by
trainees of baabtra as a part of mentoring
program. This is not official document of baabtra –
Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System
Technologies Pvt . Ltd
Did this presentation help you??? do visit our
 page facebook.com/baabtra and like us.

www.baabtra.com |
www.massbaab.com |
www.baabte.com |
Contact Us

Weitere ähnliche Inhalte

Was ist angesagt?

Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionPritom Chaki
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in javaAhsan Raja
 
Super Keyword in Java.pptx
Super Keyword in Java.pptxSuper Keyword in Java.pptx
Super Keyword in Java.pptxKrutikaWankhade1
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in JavaJava2Blog
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonSujith Kumar
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaMadishetty Prathibha
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Conceptsthinkphp
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and InterfaceHaris Bin Zahid
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methodsShubham Dwivedi
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVAVINOTH R
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 

Was ist angesagt? (20)

Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaion
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Super Keyword in Java.pptx
Super Keyword in Java.pptxSuper Keyword in Java.pptx
Super Keyword in Java.pptx
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Abstract class
Abstract classAbstract class
Abstract class
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 

Andere mochten auch

2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and OverridingMichael Heron
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)Alok Kumar
 
Overloading in java
Overloading in javaOverloading in java
Overloading in java774474
 
Constructor in java
Constructor in javaConstructor in java
Constructor in javaHitesh Kumar
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingShivam Singhal
 
JAVA Polymorphism
JAVA PolymorphismJAVA Polymorphism
JAVA PolymorphismMahi Mca
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...cprogrammings
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overridingRajab Ali
 

Andere mochten auch (20)

Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
 
Method overriding in java
Method overriding in javaMethod overriding in java
Method overriding in java
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)
 
Overloading in java
Overloading in javaOverloading in java
Overloading in java
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
JAVA Polymorphism
JAVA PolymorphismJAVA Polymorphism
JAVA Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Function Overlaoding
Function OverlaodingFunction Overlaoding
Function Overlaoding
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Function overloading
Function overloadingFunction overloading
Function overloading
 

Ähnlich wie Method overloading

java Method Overloading
java Method Overloadingjava Method Overloading
java Method Overloadingomkar bhagat
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class featuresRakesh Madugula
 
Chapter 4 Absolute Java
Chapter 4 Absolute Java Chapter 4 Absolute Java
Chapter 4 Absolute Java Shariq Alee
 
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
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...vekariyakashyap
 
chap 6 : Objects and classes (scjp/ocjp)
chap 6 : Objects and classes (scjp/ocjp)chap 6 : Objects and classes (scjp/ocjp)
chap 6 : Objects and classes (scjp/ocjp)It Academy
 
METHODS OR FUNCTIONS IN C for dotnet.pptx
METHODS OR FUNCTIONS IN C for dotnet.pptxMETHODS OR FUNCTIONS IN C for dotnet.pptx
METHODS OR FUNCTIONS IN C for dotnet.pptxArjunKhanal8
 
Lec 1.4 Object Oriented Programming
Lec 1.4 Object Oriented ProgrammingLec 1.4 Object Oriented Programming
Lec 1.4 Object Oriented ProgrammingBadar Waseer
 
Ifi7184 lesson5
Ifi7184 lesson5Ifi7184 lesson5
Ifi7184 lesson5Sónia
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesSakkaravarthiS1
 
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
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4dplunkett
 

Ähnlich wie Method overloading (20)

java Method Overloading
java Method Overloadingjava Method Overloading
java Method Overloading
 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
28c
28c28c
28c
 
28csharp
28csharp28csharp
28csharp
 
Chapter 4 Absolute Java
Chapter 4 Absolute Java Chapter 4 Absolute Java
Chapter 4 Absolute Java
 
Chap4java5th
Chap4java5thChap4java5th
Chap4java5th
 
Overloadingmethod
OverloadingmethodOverloadingmethod
Overloadingmethod
 
Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 
Constructors and Method Overloading
Constructors and Method OverloadingConstructors and Method Overloading
Constructors and Method Overloading
 
Bad Smell In Codes 1
Bad Smell In Codes 1Bad Smell In Codes 1
Bad Smell In Codes 1
 
chap 6 : Objects and classes (scjp/ocjp)
chap 6 : Objects and classes (scjp/ocjp)chap 6 : Objects and classes (scjp/ocjp)
chap 6 : Objects and classes (scjp/ocjp)
 
METHODS OR FUNCTIONS IN C for dotnet.pptx
METHODS OR FUNCTIONS IN C for dotnet.pptxMETHODS OR FUNCTIONS IN C for dotnet.pptx
METHODS OR FUNCTIONS IN C for dotnet.pptx
 
Lec 1.4 Object Oriented Programming
Lec 1.4 Object Oriented ProgrammingLec 1.4 Object Oriented Programming
Lec 1.4 Object Oriented Programming
 
Lec4
Lec4Lec4
Lec4
 
Ifi7184 lesson5
Ifi7184 lesson5Ifi7184 lesson5
Ifi7184 lesson5
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and InterfacesUNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
 
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
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
 

Mehr von baabtra.com - No. 1 supplier of quality freshers

Mehr von baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Method overloading

  • 1.
  • 2. METHOD OVERLOADING vishnukishorbabu@gmail.com @Vishnu_Kishor
  • 3. METHOD • A collection of statements that are grouped together to perform an operation • A method has the following syntax modifier return_Value_Type Method_Name(list of parameters) { // Method body; } • A method definition consists of a method header and a method body
  • 4. PARTS OF METHOD 1. Modifiers: – Optional – Tells the compiler how to call the method. – Defines the access type of the method. 2. Return Types – The data type of the value the method returns. – the return type is the keyword void when no value is returned
  • 5. • Method Name – The actual name of the method. – Method name and the parameter list together constitute the method signature. • Parameters – Act as a placeholder. – When a method is invoked, a value is passed to parameter. – This value is referred to as actual parameter or argument. – The parameter list refers to the type, order, and number of the parameters of a method. – Parameters are optional; that is,
  • 6. • Method Body – The method body contains a collection of statements that define what the method does.
  • 7. METHOD OVERLOADING • A concept in Java which allows programmer to declare method with same name but different behavior • Method with same name co-exists in same class but they must have different method signature • Resolved using static binding in Java at compile time • When you overload a method in Java its method signature gets changed
  • 8. How to overload a method in Java • If you have two methods with same name in one Java class with different method signature than its called overloaded method in Java • Generally overloaded method in Java has different set of arguments to perform something based on different number of input • Binding of overloading method occurs during compile time and overloaded calls resolved using static binding. • To overload a Java method just changes its signature.
  • 9. • To change signature, either change number of argument, type of argument or order of argument • Since return type is not part of method signature changing return type will result in duplicate method and you will get compile time error in Java
  • 10. Static and Dynamic Binding • Binding-process used to link which method or variable to be called as result of their reference in code • Two types of binding – Static Binding, and – Dynamic Binding.
  • 11. • Static binding in Java occurs during Compile time while Dynamic binding occurs during Runtime. • private, final and static methods and variables uses static binding and bonded by compiler while virtual methods are bonded during runtime based upon runtime object. • Static binding uses class information for binding while Dynamic binding uses Object to resolve binding. • Overloaded method are bonded using static binding while overridden methods are bonded during compile time. – Method override -A method in subclass has the same name & type signature as a method in its superclass.
  • 12. Example public class MethodOverLoading { // Method 1 public static int Addition(int a, int b) { System.out.println(“Method 1 is called”); return a + b; } // Method 2 public static int Addition(int a, int b, int c) { System.out.println(“Method 2 is called”); return a + b + c; } }
  • 13. public static void main(String[] args) { int Answer1 = Addition(5, 6); // In this case Method 1 will be called System.out.println(“Answer 1 = ” + Answer1); System.out.println(“----------------------------”); int Answer2 = Addition(5, 6, 7); // In this case Method 2 will be called System.out.println(“Answer 2 = ” + Answer2); }
  • 14. Output of the code Method 1 is called Answer 1 = 11 ---------------------------- Method 2 is called Answer 2 = 18
  • 16. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra – Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 17. Did this presentation help you??? do visit our page facebook.com/baabtra and like us. www.baabtra.com | www.massbaab.com | www.baabte.com |