Overriding and Overloading: What is the difference?
Overloading and overriding are different aspects of
polymorphism.
Overloading and Overriding: What is the differenc |
Example:
Base Class:
-------------------------------
public class BaseClass
{
public virtual void
Method1()
{
Print("Base
Class Method");
}
}
Derived class
-----------------------------
public class DerivedClass: BaseClass
{
public override void
Method1()
{
Print("Derived
Class Method");
}
}
Usage
--------------------------
public class Sample
{
public void
TestMethod()
{
DerivedClass objDC
= new DerivedClass();
objDC.Method1();
BaseClass objBC =
(BaseClass)objDC;
objDC.Method1();
}
}
Result
---------------------
Derived Class Method
Derived Class Method
difference in between Overriding and Overloading, real world
example and live code example on Overriding and Overloading, use of Overriding
and Overloading in c sharp #