---
title: "Function overriding versus overloading"
subject: "Object Oriented Programming"
chapter: 6
key: "semester_3/object_oriented_programming:function-overriding-vs-overloading"
source: https://www.bctengineer.com/q/semester_3/object_oriented_programming/function-overriding-vs-overloading
site: BCT Engineering
---

# Function overriding versus overloading

Object Oriented Programming · Chapter 6: Inheritance

- Asked in: 2074 Asoj, 5 marks; 2072 Kartik, 4 marks (asked 2 times)
- Video: [Lec-56: Function Overriding vs Overloading | Runtime Polymorphism in C++](https://www.youtube.com/watch?v=iUXwbydT2J4) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/object_oriented_programming/function-overriding-vs-overloading
- Whole chapter: https://www.bctengineer.com/md/semester_3/object_oriented_programming/chapter-6

## Question

How does function overriding differ from function overloading? Explain with example.

## Short answer

Function overloading is having multiple functions with the same name but different parameter lists in the same class, resolved at compile time. Function overriding is redefining a base class function in a derived class with identical signature; with virtual, it enables runtime polymorphism.

## Answer

**Function overloading** means having several functions with the same name in the same scope but different parameter lists (number, type or order of parameters). **Function overriding** means a derived class redefines a base class function that has the same name, return type and parameters.

| Point | Overloading | Overriding |
|---|---|---|
| Scope | Same class (same scope) | Base and derived class |
| Signature | Must differ in parameters | Must be identical |
| Inheritance | Not required | Required |
| Binding | Compile time (early) | Run time if `virtual`, else compile time |
| `virtual` keyword | Not used | Used for run-time polymorphism |
| Purpose | Same operation on different data types | Change base behaviour in derived class |

**Example of overloading:**

```cpp
class Calc {
public:
    int add(int a, int b)       { return a + b; }
    double add(double a, double b) { return a + b; }   // different types
};
```

**Example of overriding:**

```cpp
#include <iostream>
using namespace std;

class Animal {
public:
    virtual void sound() { cout << "Some sound" << endl; }
};
class Dog : public Animal {
public:
    void sound() { cout << "Bark" << endl; }   // overrides Animal::sound
};

int main() {
    Animal *p = new Dog;
    p->sound();          // Bark (decided at run time)
    delete p;
    return 0;
}
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which describes function overloading?
   A. Same name in the same scope with different parameter lists
   B. Same name and signature in base and derived class
   C. Different names, same parameters
   D. Same function in two classes
   Answer: A. Overloading needs different parameters in the same scope. (Key point: Overloading definition)

2. Which statement about binding is correct?
   A. Overloading is run-time; overriding is always compile-time
   B. Both are run-time
   C. Overloading is compile-time; virtual overriding is run-time
   D. Both are compile-time
   Answer: C. Overloading is resolved at compile time; virtual overriding at run time. (Key point: Binding)

3. Which needs inheritance?
   A. Overloading
   B. Neither
   C. Both
   D. Overriding
   Answer: D. Overriding redefines a base function in a derived class, so it needs inheritance. (Key point: Inheritance)

4. With Animal* p = new Dog and virtual sound(), what does p->sound() print?
   A. Some sound
   B. Bark
   C. Nothing
   D. Compile error
   Answer: B. Virtual dispatch chooses Dog's version at run time. (Key point: Example output)

## Related in Object Oriented Programming

- [Function overriding and how to resolve it](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afunction-overriding-resolve) — Object Oriented Programming, chapter 6
- [Default arguments and function overloading](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Adefault-args-function-overloading) — Object Oriented Programming, chapter 3, asked 5×
- [Function overloading; new/delete average program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afunction-overloading-new-delete-average) — Object Oriented Programming, chapter 3
- [Need of template; function template overloading](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Awhy-template-function-overloading) — Object Oriented Programming, chapter 9
- [Member function overriding with virtual function](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Avirtual-member-override-reason) — Object Oriented Programming, chapter 7
- [Overloading via member and non-member function](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Amember-vs-nonmember-overload) — Object Oriented Programming, chapter 5

## Related in other subjects

- [Switch versus user defined function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aswitch-vs-user-function) — Computer Programming, chapter 5
