Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconFull Stack Developmentbreadcumb forward arrow iconDifference Between Overloading and Overriding | Overloading vs Overriding

Difference Between Overloading and Overriding | Overloading vs Overriding

Last updated:
15th Jun, 2021
Views
Read Time
5 Mins
share image icon
In this article
Chevron in toc
View All
Difference Between Overloading and Overriding | Overloading vs Overriding

Introduction

Object Oriented Programming plays an important role in the software development sectors. Several concepts are associated with this type of programming like class, object, polymorphism, inheritance, data abstraction, generic programming, and exceptional handling.

The developers always find the concept of polymorphism to be quite interesting which has sub-concepts like method overloading, method overriding, etc. However, to understand the concept of polymorphism better, the difference between overloading and overriding has to be understood.

Explore our Popular Software Engineering Courses

Check out our free courses to get an edge over the competition.

Difference Between Method Overloading and Method Overriding

A lot of differences exist between method overloading and method overriding. The list of differences between method overloading and overriding in java are tabulated below:

Ads of upGrad blog

Check out upGrad’s Advanced Certification in Blockchain

Method OverloadingMethod Overriding
1The method is used for increasing the readability of the program.The method is used to provide the implementation of the method that is provided by the superclass.
2It is performed within a classOccurs in two classes having IS-A (inheritance) relationship. The base and a child class are required for overriding.
3Methods or functions must have the same name and different signatures.Methods or functions must have the same name and same signatures.
4The parameters used in this method should be different.The same parameters should be used in the case of method overriding.
5It is an example of compile-time polymorphism. The binding of the overloading method call to its definition happens at the compile time.It is an example of run time polymorphism. The binding of the overridden method call to its definition happens at the run time.
6Only by changing the return type, the method overloading can’t be performed. The return type may be different or the same. But, the parameters should be different.The return type in method overriding might be the same or covariant.
7Method overloading might be applied to static methods. This means a class can have more than one static method of the same name.Method overriding cannot be applied to static methods.
8Static binding is being used for method overloading.Dynamic binding is being used for method overriding.
9Better performance is given by method overloading.Lesser performance compared to method overloading. The reason is that binding of overridden methods is being done at runtime.
10Private and final methods can be overloaded. A class can have more than one private/final method of the same name.Private and final methods cannot be overridden. A child class cannot override the private/final methods of their base class.
11Inheritance may or may not be required in case of method overloading.Inheritance is always required in the case of method overriding.
12It is used in order to add more to the behavior of methods.It is used in order to change the behavior of existing methods.
13There is no need for the presence of more than one class in method overloading.There is always the need for at least two classes in method overriding.
14If overloading breaks, the compile-time error will come and it’s easy to fix.If overriding breaks, it can cause serious issues in our program because the effect will be visible at runtime.
15The method overloading must have a different signature.The method overriding must have the same signature.
16The access modifiers in the overloading method can be anything or different.The subclass method’s access modifier must be the same or higher than the superclass method access modifier in the overriding method.
17Exceptions thrown can be anything in the concept of method overloading.In method overriding, the unchecked exceptions thrown may be anything. For checked exceptions, the overriding method should not throw any exceptions that are new or broader than the ones declared by the overridden method.
18The compiler always takes care of the method resolution based on the reference type.The JVM takes care of the method resolution based on the runtime object.

Explore Our Software Development Free Courses

upGrad’s Exclusive Software Development Webinar for you –

SAAS Business – What is So Different?

Ads of upGrad blog

 

Learn Software Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

In-Demand Software Development Skills

Check out upGrad’s Advanced Certification in Cyber Security

What Next?

If you’re interested to learn more about full-stack software development, check out upGrad & IIIT-B’s Executive PG Program in Full-Stack Software Development which is designed for working professionals and offers 500+ hours of rigorous training, 9+ projects and assignments, IIIT-B Alumni status, practical hands-on capstone projects & job assistance with top firms.

Read our Popular Articles related to Software Development

Profile

Rohan Vats

Blog Author
Software Engineering Manager @ upGrad. Passionate about building large scale web apps with delightful experiences. In pursuit of transforming engineers into leaders.

Frequently Asked Questions (FAQs)

1What is runtime polymorphism?

Runtime polymorphism is a kind of polymorphism that involves dynamic typing. This means that objects can be manipulated as if they were a single type. This is similar to static polymorphism where objects are manipulated as if they had a single type, regardless of their underlying type. It is one of the five major software design principles. It is used with object-oriented programming. It means that a variable can refer to different objects depending upon the run time conditions. For example, a variable may be used to refer to a Dog object when the variable is declared, but during the execution of the program, the variable may refer to a Cat object. It is an automatic type conversion. For example, if you have an integer variable i, and you assign a string value to it, it will become a string variable.

2How overriding is different from Overloading?

3Can we override the overloaded method?

An overloaded method is the same as a regular one (in terms of number and type of the parameters), but with the difference that the overloaded method is written in such a way that it can accept parameters of a different type than the regular one. You can override an overloaded method in the same way as you override a regular one.