0
What is overriding
5 Respuestas
+ 2
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
+ 1
"The ability of a subclass to override a method allows a class to inherit from a superclass whose behavior is "close enough" and then to modify behavior as needed. The overriding method has the same name, number and type of parameters, and return type as the method that it overrides."
One of the simplest example – Here Boy class extends Human class. Both the classes have a common method void eat(). Boy class is giving its own implementation to the eat() method or in other words it is overriding the method eat().
class Human{
public void eat() {
System.out.println("Human is eating");
}
}
class Boy extends Human{
public void eat(){
System.out.println("Boy is eating");
}
public static void main( String args[]) {
Boy obj = new Boy();
obj.eat();
}
}
Output:
Boy is eating
+ 1
Anmol, that is overloading.
0
yes
0
No, The overriding method has the same name, number and type of parameters, and return type as the method that it overrides.
If two or more methods having same name and their argument lists are different.it is called method Overloading.in this case method return type doesn't matter all depends on number of arguments and thier type.