Hi Guest

MobileUser

1 HomePage 1 Jobs 1 WalkIn 1Articles  

Cat Exam

 :) Latest Topic
AJAX
VB.NET
SQL Query
UDDI
CLASS
JavaScript Questions
SharePoint Interview
SilverLight
WCF
general knowledge
 ASP.NET
 :) Hot Jobs
 
 :) Latest Articles


  

 


Function or Method Overload Ways with Example
Question Posted on 03 Feb 2017

Home >> OOPS >> CLASS >> Function or Method Overload Ways with Example




If any class which have multiple methods with same name but have different parameters then they are said overloaded. In Function Overloading we use the same name for different functions to do same or different operations on same class.
We used this where we have to perform any operation with some different number of arguments.

There are mainly two ways function overload or method overload:-

1.By changing number of Arguments.
2.By having different types of argument.

Now example of above two ways are given below

(1)By changing number of Arguments.

int sum (int x, int y)
{
   ///some operations
}

int sum(int x, int y, int z)
{
   ///some operations
}


2.By having different types of argument.

int sum(int x,int y)
{
   ///some operations
}
double sum(double x,double y)
{
   ///some operations
}


Now take a Full example how to define and call overloading methods

using System;
namespace oopsfuntionoverload
{
   class funOverloadexam
   {
     public string namevalue;
     //Now start overloaded functions
     public void setFunctionName(string var1)
     {
        name = var1;
     }

     public void setFunctionName(string var2, string var1)
     {
        name = var2 + "" + var1;
     }

     public void setFunctionName(string var3, string var2, string var1)
     {
       name = var3 + "" + var2 + "" + var1;
     }

     //Entry point
     static void Main(string[] args)
     {
       funOverloadexam obj = new funOverloadexam();
       obj.setFunctionName("barack");
       obj.setFunctionName("barack "," obama ");
       obj.setFunctionName("barack ","hussian","obama");
     }
   }
}
0
0



 
 Input Your Comments Or suggestions(If Any)
 Name
 Email(optional)
 Comments


Other Important Questions
difference between classes and struct
Function or Method Overload Ways with Example
Types of Inheritance OOPS
Can we create a instance of abstract class object
what is constructor and its types with example






 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |