crackyourinterview.com


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

Function or Method Overload Ways with Example
Question Posted on 03 Feb 2017Home >> 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...

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

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres 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






@2014-2022 Crackyourinterview (All rights reserved)
Privacy Policy - Disclaimer - Sitemap