0

What is overriding

23rd Feb 2017, 1:43 AM
Shashi
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
11th Sep 2017, 3:11 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 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
23rd Feb 2017, 2:14 AM
Eranga
Eranga - avatar
+ 1
Anmol, that is overloading.
23rd Feb 2017, 5:43 AM
1of3
1of3 - avatar
0
yes
23rd Feb 2017, 4:03 AM
THEJAS.P
THEJAS.P - avatar
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.
23rd Feb 2017, 4:18 AM
Eranga
Eranga - avatar