SlideShare a Scribd company logo
1 of 12
PRESENTATION ON
OVERLOADING
Method Overloading 1tMyn
CONTENTS
Method Overloading 2tMyn
 Introduction to overloading
 Method overloading
 Example program for method overloading
Introduction to overloading
Method Overloading 3tMyn
  Overloading allows functions in computer
languages such as C++ and C# to have the same
function name but with different parameters.
 Overloading comes under static polymorphism.
 Static polymorphism can be achieved within the
class.
 The number of parameters and data type
of parameters must be different.It is showm
in the following example.
 Example:
Add()
Add(int i)
Add(int i,int j)
Add(int i,double j)
Add(double i,double j)
Method Overloading tMyn 4
Method overloading
 The process of creating more than one method in
a class with same name or creating a method in
derived class with same name as a method in
base class is called as method overloading.
In VB.net when you are overloading a method of
the base class in derived class, then you must use
the keyword “Overloads”.
But in C# no need to use any keyword while
overloading a method either in same class or in
derived class.
Method Overloading tMyn 5
While processing overloading methods, a
rule must be follow i.e, the overloaded
methods must differ either in number of
arguments they take or the data type of at
least one argument
Method overloading is commonly used to
create several methods with the same
name that perform the same or similar
tasks, but on different types or different
numbers of arguments.
6
EXAMPLE:
using System;
namespace ProgramCall
{
class Class1
{
public int Sum(int A, int B)
{
return A + B;
}
7
public float Sum(int A, float B)
{
return A + B;
}
}
class Class2 : Class1
{
public int Sum(int A, int B, int C)
{
return A + B + C;
}
}
l 8
class MainClass
{
static void Main()
{
Class2 obj = new Class2();
Console.WriteLine(obj.Sum(10, 20));
Console.WriteLine(obj.Sum(10,
15.70f));
Method Overloading tMyn 9
Console.WriteLine(obj.Sum(10, 20, 30));
Console.Read();
}
}
}
Output :
30
25.7
60
Method Overloading tMyn 10
The compiler distinguishes overloaded methods by their
signature :
 A combination of the method’s name ,data types and
order of its parameters.
 If the compiler looked only at method names during
compilation, the code in previous example would be
ambiguous.
 Overloaded method calls cannot be distinguished by
return type.
11
C# Method overloading

More Related Content

What's hot

Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
Methods and constructors
Methods and constructorsMethods and constructors
Methods and constructors
Ravi_Kant_Sahu
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 
Java Collections
Java CollectionsJava Collections
Java Collections
parag
 

What's hot (20)

Classes objects in java
Classes objects in javaClasses objects in java
Classes objects 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)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
constructor and destructor-object oriented programming
constructor and destructor-object oriented programmingconstructor and destructor-object oriented programming
constructor and destructor-object oriented programming
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Data types in java
Data types in javaData types in java
Data types in java
 
OOP java
OOP javaOOP java
OOP java
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Method overriding
Method overridingMethod overriding
Method overriding
 
class and objects
class and objectsclass and objects
class and objects
 
Methods and constructors
Methods and constructorsMethods and constructors
Methods and constructors
 
C# in depth
C# in depthC# in depth
C# in depth
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Java Collections
Java CollectionsJava Collections
Java Collections
 

Similar to C# Method overloading

Data structures and algorithms lab2
Data structures and algorithms lab2Data structures and algorithms lab2
Data structures and algorithms lab2
Bianca Teşilă
 

Similar to C# Method overloading (20)

Polymorphism in java
Polymorphism in java Polymorphism in java
Polymorphism in java
 
Lecture_7 Method Overloading.pptx
Lecture_7 Method Overloading.pptxLecture_7 Method Overloading.pptx
Lecture_7 Method Overloading.pptx
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Overloadingmethod
OverloadingmethodOverloadingmethod
Overloadingmethod
 
4. method overloading
4. method overloading4. method overloading
4. method overloading
 
JAVA_POLYMORPHISM.pptx
JAVA_POLYMORPHISM.pptxJAVA_POLYMORPHISM.pptx
JAVA_POLYMORPHISM.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)Java Polymorphism: Types And Examples (Geekster)
Java Polymorphism: Types And Examples (Geekster)
 
Polymorphism in Java by Animesh Sarkar
Polymorphism in Java by Animesh SarkarPolymorphism in Java by Animesh Sarkar
Polymorphism in Java by Animesh Sarkar
 
Introduction to method overloading & method overriding in java hdm
Introduction to method overloading & method overriding  in java  hdmIntroduction to method overloading & method overriding  in java  hdm
Introduction to method overloading & method overriding in java hdm
 
Method overloading in java
Method overloading in javaMethod overloading in java
Method overloading in java
 
‫Chapter3 inheritance
‫Chapter3 inheritance‫Chapter3 inheritance
‫Chapter3 inheritance
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptx
 
Overloading
OverloadingOverloading
Overloading
 
Thin Template Explained
Thin Template ExplainedThin Template Explained
Thin Template Explained
 
Polymorphism.pptx
Polymorphism.pptxPolymorphism.pptx
Polymorphism.pptx
 
Data structures and algorithms lab2
Data structures and algorithms lab2Data structures and algorithms lab2
Data structures and algorithms lab2
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Java execise
Java execiseJava execise
Java execise
 

More from Prem Kumar Badri

More from Prem Kumar Badri (20)

Module 15 attributes
Module 15 attributesModule 15 attributes
Module 15 attributes
 
Module 14 properties and indexers
Module 14 properties and indexersModule 14 properties and indexers
Module 14 properties and indexers
 
Module 12 aggregation, namespaces, and advanced scope
Module 12 aggregation, namespaces, and advanced scopeModule 12 aggregation, namespaces, and advanced scope
Module 12 aggregation, namespaces, and advanced scope
 
Module 13 operators, delegates, and events
Module 13 operators, delegates, and eventsModule 13 operators, delegates, and events
Module 13 operators, delegates, and events
 
Module 11 : Inheritance
Module 11 : InheritanceModule 11 : Inheritance
Module 11 : Inheritance
 
Module 10 : creating and destroying objects
Module 10 : creating and destroying objectsModule 10 : creating and destroying objects
Module 10 : creating and destroying objects
 
Module 9 : using reference type variables
Module 9 : using reference type variablesModule 9 : using reference type variables
Module 9 : using reference type variables
 
Module 8 : Implementing collections and generics
Module 8 : Implementing collections and genericsModule 8 : Implementing collections and generics
Module 8 : Implementing collections and generics
 
Module 7 : Arrays
Module 7 : ArraysModule 7 : Arrays
Module 7 : Arrays
 
Module 6 : Essentials of Object Oriented Programming
Module 6 : Essentials of Object Oriented ProgrammingModule 6 : Essentials of Object Oriented Programming
Module 6 : Essentials of Object Oriented Programming
 
Module 5 : Statements & Exceptions
Module 5 : Statements & ExceptionsModule 5 : Statements & Exceptions
Module 5 : Statements & Exceptions
 
Module 4 : methods & parameters
Module 4 : methods & parametersModule 4 : methods & parameters
Module 4 : methods & parameters
 
Module 3 : using value type variables
Module 3 : using value type variablesModule 3 : using value type variables
Module 3 : using value type variables
 
Module 2: Overview of c#
Module 2:  Overview of c#Module 2:  Overview of c#
Module 2: Overview of c#
 
Module 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET PlatformModule 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET Platform
 
C# Non generics collection
C# Non generics collectionC# Non generics collection
C# Non generics collection
 
C# Multi threading
C# Multi threadingC# Multi threading
C# Multi threading
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
 
C# Generic collections
C# Generic collectionsC# Generic collections
C# Generic collections
 
C# Global Assembly Cache
C# Global Assembly CacheC# Global Assembly Cache
C# Global Assembly Cache
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
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 setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
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)
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

C# Method overloading

  • 2. CONTENTS Method Overloading 2tMyn  Introduction to overloading  Method overloading  Example program for method overloading
  • 3. Introduction to overloading Method Overloading 3tMyn   Overloading allows functions in computer languages such as C++ and C# to have the same function name but with different parameters.  Overloading comes under static polymorphism.  Static polymorphism can be achieved within the class.
  • 4.  The number of parameters and data type of parameters must be different.It is showm in the following example.  Example: Add() Add(int i) Add(int i,int j) Add(int i,double j) Add(double i,double j) Method Overloading tMyn 4
  • 5. Method overloading  The process of creating more than one method in a class with same name or creating a method in derived class with same name as a method in base class is called as method overloading. In VB.net when you are overloading a method of the base class in derived class, then you must use the keyword “Overloads”. But in C# no need to use any keyword while overloading a method either in same class or in derived class. Method Overloading tMyn 5
  • 6. While processing overloading methods, a rule must be follow i.e, the overloaded methods must differ either in number of arguments they take or the data type of at least one argument Method overloading is commonly used to create several methods with the same name that perform the same or similar tasks, but on different types or different numbers of arguments. 6
  • 7. EXAMPLE: using System; namespace ProgramCall { class Class1 { public int Sum(int A, int B) { return A + B; } 7
  • 8. public float Sum(int A, float B) { return A + B; } } class Class2 : Class1 { public int Sum(int A, int B, int C) { return A + B + C; } } l 8
  • 9. class MainClass { static void Main() { Class2 obj = new Class2(); Console.WriteLine(obj.Sum(10, 20)); Console.WriteLine(obj.Sum(10, 15.70f)); Method Overloading tMyn 9
  • 11. The compiler distinguishes overloaded methods by their signature :  A combination of the method’s name ,data types and order of its parameters.  If the compiler looked only at method names during compilation, the code in previous example would be ambiguous.  Overloaded method calls cannot be distinguished by return type. 11