Professional Documents
Culture Documents
What Is The Difference Between Overriding and Overloading A Method? Explain How Both Are Done
What Is The Difference Between Overriding and Overloading A Method? Explain How Both Are Done
Overloading
Overloading is when you have multiple methods in the same scope(class), with the same
name but different signatures.
Creating the method in a derived class with same name, same parameters and same return type as
in base class is called as method overriding.
//Overloading
public class test
{
public void getStuff(int id)
{}
public void getStuff(string name)
{}
}
Overriding
Overriding is a principle that allows you to change the functionality of a method in a child
class.
Creating a multiple methods in a class with same name but different parameters and types is called
as method overloading.method overloading is the example of Compile time polymorphism which
is done at compile time.
//Overriding
public class test
{
public virtual void getStuff(int id)
{
//Get stuff default location
}
}
Compile time error is any type of error that prevent a c# program compile like a
syntax error, a class not found, a bad file name for the defined class, a possible
loss of precision when you are mixing different java data types and so on. A runtime
error means an error which happens, while the program is running.
Managed code, Managed code is computer program code that requires and will execute
only under the management of a Common Language Runtime virtual machine, typically
the .NET Framework, or Mono.
Managed code is .NET code (VB.NET, C# etc.) that you write and compile to .NET CIL.
Unmanaged code is code that is not under .NET that compiles to direct machine code.