top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Difference between overloading and overriding in C++ ?

+1 vote
2,851 views

Please explain with basic example.Am new to programming

posted Jul 23, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

Few points should help you:

  • Overloading is when multiple function with same name exist in a class. Overriding is when function have same prototype in base class as well as derived class.
  • Overriding occurs when one class is inherited from another class whereas overloading can occur without inheritance.
  • Overloaded functions must differ in either number of parameters or type whereas in Overridden function parameters must be same.

Also check this video

answer Jul 23, 2014 by Salil Agrawal
0 votes

1.In overloading,there is a relation ship between methods available in the same class where as in overridding,there is relationship between a super class method and subclass method.
2.Overloading doesn't block inheritence from the superclass where as overridding blocks inheritence.
3.In overloading,seperate methods share the same name where as in overridding,subclass methods replaces the superclass.
4.Overloading must have different method signatures where as overriding must have same signature.

Example

Overriding

public class MyBaseClass
{
    public virtual void MyMethod()
    {
        Console.Write("My BaseClass Method");

    }
}
public class MyDerivedClass : MyBaseClass
{
    public override void MyMethod()
    {
        Console.Write("My DerivedClass Method");

    }
}

Overloading

int add(int a, int b)
int add(float a , float b)
answer Nov 20, 2014 by Manikandan J
Similar Questions
+1 vote

void fun1(int x, int y) { } and void fun1(int const x, int const y) { } can't be overloaded while
void fun1(int *x, int *y){ } and void fun1(int const *x , int const *y) { } can be overloaded. I compiled both the samples and found first set of functions can't be overloaded while the next two functions can be overloaded. I could not understand the reason behind it.

...