+ 8
What is the different between overriding and overloading in java?
4 Respostas
+ 4
overloading:
if u have same function name with different parameter or arguments with in the same class.
overriding:
if u have base class and derived class,then u are override the base class method in the derived class with same function name,parameters and return type.
+ 2
To add to the other answer. Examples.
Overloading:
public int sum(int a, int b) {...}
public int sum(int a, int b, int c) {...}
Overriding:
class A {
public int mult(int x, int y) {...}
}
class B extends A {
@Override public int mult(int x, int y) {...}
}
In the first case, sum is overloaded because it can be run with different parameters. In the second case, mult is overridden by class B to use a different implementation.
+ 1
Overloading occurs when two or more methods in one class have the same method name but different parameter.
__________________________
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.
+ 1
here is an example that you may want to check to see difference or understand the meanings of overriding and overloading https://code.sololearn.com/c0awDMpDLukF/?ref=app