Method Overloading and Method Overriding are both the techniques used to implement FUNCTIONAL POLYMORPHISM
They enhance the methods functionality using their respective features.
1) It involves having another method with the same name in a class or its derived class.
2)can be implemented with or without inheritance.
3)It is implemented by:
a)changing the number of parameters in different methods with same name.
b)changing the parameter data types (if the number of parameters are same)
c)changing parameter order.
4)applicable to static as well as non static methods:
5)no keywords needed before the method names in C#.
6)also called as COMPILE TIME Polymorphism.
example: int add(int a, int b)
int add(int a)
1) It involves having another method with the same name in a base class and derived class.
2)always needs inheritance.
3)It is implemented by having two methods with same name, same signature, but different implementations (coding)in a base class and derived class
4)applicable to nonstatic, nonprivate methods only.access modifiers of the methods are not changed in the base and derived classes.
5)virtual and override keywords are needed before the method names in base and derived classes.
For overriding in firther classes, override keyword will be used,
6)RUN TIME Polymorphism
public virtual void demo()
public override void demo()
static void Main()
B obj=new B();
Asked In: Many Interviews |