What is difference between method overloading and method overriding in java? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita

What is difference between method overloading and method overriding in java?

Java feature

18th Sep 2019, 4:36 AM
Gamerūüėé - avatar
4 Respuestas
+ 4
https://www.sololearn.com/Discuss/1894429/what-is-the-difference-between-method-overloading-and-method-overriding https://www.programcreek.com/2009/02/overriding-and-overloading-in-java-with-examples/ Overloading occurs when two or more methods in one class have the same method name but different parameters. Overriding means having two methods with the same method name and parameters (i.e., method signature). One of the methods is in the parent class and the other is in the child class. Overriding allows a child class to provide a specific implementation of a method that is already provided its parent class.
18th Sep 2019, 4:42 AM
Phurinat Puekkham
Phurinat Puekkham - avatar
+ 2
In the case of method overloading we have the same name and the same signature but in the case of method overriding the whole prototype is same . Again, the method overloading is basically use when we want to do different work with only one function and in the other hand the method overriding is happen when we inherit a class from anthor class to change the implementation of that particular function.
18th Sep 2019, 9:49 AM
Ronak Paul
Ronak Paul - avatar
+ 2
Read the tutorial carefully and don't post unescessary questions.... https://www.sololearn.com/learn/Java/2165/ Please don't spam the Q&A Section...Don't copy....
2nd Oct 2019, 5:10 AM
Subhransuūü§ėūüŹĽūü§ėūüŹĽ - avatar
+ 1
METHOD OVERLOADING: take an example public void method(){ //some logic } public void method(int a){ //some logic } let’s compare above methods -they have same method name -different signature i.e input parameters -the return type may or may not be equal. if you want to use the method, the program choses the method having the same signature you called. ex: if you call method(10); it calls second method as it matches with the signature. METHOD OVERRIDING: if you extended or implemented a class or an interface , you has to implement the methods of that super class as per you requirement. in this case you had to implement or override the logic of that method. ex: consider an interface and a class public Interface{ public void method(); } public class implements Interface{ @Override public void method(){ //develop your own logic } } take the same method from the super class and you just has to change the logic.
18th Sep 2019, 6:20 PM
Sai Ram