Categories: Java

Difference between method overloading and method overriding

In Java, there are numerous distinctions between method overloading and method overriding. The following is a list of the differences between method overloading and method overriding:

No.Method OverloadingMethod Overriding
1)To make the program more readable, method overloading is used.Method overriding is used to provide a specific implementation of a method that its superclass already provides.
2)Within a class, method overloading is done.Method overriding occurs in two classes that have IS-A (inheritance) relationship.
3)When overloading a method, the parameter must be different.When overriding a method, the parameter must be the same.
4)Compile-time polymorphism is demonstrated by method overloading.Run-time polymorphism is demonstrated by method overriding.
5)In Java, method overloading is not possible by simply changing the method’s return type. In method overloading, the return type can be the same or different. However, you must alter the parameter.In method overriding, the return type must be the same or covariant.

Note: also read about the Runtime Polymorphism

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Share
Published by
Rabecca Fatima

Recent Posts

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is…

1 year ago

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…

1 year ago

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is…

1 year ago

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is…

1 year ago

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…

1 year ago

Binary Search Tree (BST)

A Binary Search Tree (BST) is a type of binary tree that satisfies the following…

1 year ago