Compare the Difference Between Similar Terms

Difference Between

Home / Technology / IT / Programming / Difference Between Overriding and Overloading

Difference Between Overriding and Overloading

July 25, 2011 Posted by Indika

Overriding vs Overloading

The method Overriding and method Overloading are two concepts/techniques/feature found in some programming languages. Both concepts allow the programmer to provide different implementations for methods with the same name. Method overriding allows the programmer to provide an alternative implementation within a sub class to a method already defined inside its super class. Method overloading allows the programmer to provide different implementations to multiple methods with the same name (within the same class).

What is Overriding?

As mentioned above, a class can extend a super class or a parent class, in object oriented programming languages. A child class can have its own methods or can optionally have its own implementations to methods already defined in its parent class (or one of its grand parent classes). So when the latter happens, it is called method overriding. In other words, if the child class provides an implementation to a method with the same signature and return type as a method already defined in one of its parent classes, that method is said to be overridden (replaced) by the implementation of the child class. So, if there is an overridden method in a class, the runtime system will have to decide which method implementation is used. This issue is resolved by looking at the exact type of object that is used to invoke it. If an object of the parent class is used to invoke the overridden method, then the implementation in the parent class is used. Similarly, if it is an object of the child class that is used, then the child class’s implementation is used. Modern programming languages like Java, Eifell, C++ and Python allows method overriding.

What is Overloading?

Method overloading is a feature provided by some programming languages to create more than one method with the same name, but with different input and output types. In modern programming languages like Java, C#, C++ and VB.NET, this feature is available. You can overload a method by creating another method with the same name but with a different method signature or a different return type (or both). For example, if you have method1(type1 t1) and method1(type2 t2) inside the same class, then they are overloaded. Then the system will have to decide which one to be executed when it is called. This differentiation is made by looking at the type of the parameter(s) been passed in to the method. If the argument is of type1, then the first implementation is called, while if it is of type2, then the second implementation is called.

What is the difference between Overriding and Overloading?

Although, method overriding and method overloading are used to provide a method with different implementations, there are key differences between these two concepts/techniques. First of all, subjects of method overriding always stay within different classes, while subjects of method overloading stay within the same class. That means overriding is only possible in object oriented programming languages that allows inheritance, while overloading can be available in a non object-oriented language as well. In other words, you override a method in the super class but you overload a method within your own class.

Another difference is that overridden methods have the same method name, method signature and the return type, but overloaded methods must differ in either the signature or the return type (the name should be the same). In order to differentiate between two overridden methods, the exact type of object that is used to invoke the methods id used, whereas to differentiate between two overloaded methods the types of the parameters are used. Another key difference is that overloading is resolved at compile time, while overriding is resolved at runtime.

Related posts:

Difference Between Structured Programming and Object Oriented Programming Difference Between AOP and OOP Difference Between Object Oriented Programming and Procedural Programming Difference Between Abstract Class and Concrete Class Difference Between Exception and Error

Filed Under: Programming Tagged With: C, compile time, Eifell, Inheritance, Java, method name, method Overloading, method overridden, method Overriding, method signature, Object Oriented Programming, Overloading, overloading method, overridden method, Overriding, Python, run time, runtime system, VB.NET

About the Author: Indika

Indika, BSc.Eng, MSECE Computer Engineering, PhD. Computer Science, is an Assistant Professor and has research interests in the areas of Bioinformatics, Computational Biology, and Biomedical Natural Language Processing.

Leave a Reply Cancel reply

Request Article

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and SARS

Difference Between Coronavirus and SARS

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

You May Like

Difference Between Calcium Gluconate and Calcium Chloride

Difference Between Calcium Gluconate and Calcium Chloride

Difference Between Mein and Meine

Difference Between Versus and Verses

Difference Between Organ and Organelle

Difference Between Sony Playstation 3 (PS3) and PS3 Slim

Latest Posts

  • Difference Between SDP and RDP
  • Difference Between Masking and Demasking Agents
  • Difference Between Alcoholic and Non-alcoholic Fatty Liver
  • Difference Between Neostigmine and Physostigmine
  • Difference Between Resonance and π Conjugation
  • Difference Between Equational Division and Reduction Division
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

Copyright © 2010-2018 Difference Between. All rights reserved. Terms of Use and Privacy Policy: Legal.