Hi Guest

HomePage

1 1

To improves our performance please Like Share Subscribe(Will boost us)

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



Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




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






Most Visited Questions
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 |
     
 
Privacy policy | Terms and Conditions | Blog


If the copyright of any questions or content or syntax belong to you email us we will remove that(info@crackyourinterview.com or crackyourinterview2018@gmail.com)
 

1
Home About Us GroupChat
 
Sitemap Feedback Contact us