If the overridden method has different return type then will it produce a error ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

If the overridden method has different return type then will it produce a error ?

While overriding a method in java , if I changed the return type of overridden method i.e the overridden method will have different return type from the original method or if I changed the data type of the parameters in the overridden method, which type of error will it produce.

20th Apr 2019, 6:47 AM
RILEY
2 Answers
+ 7
Hi! Method overriding means you want to change only the content inside of the block code.(inside brackets - {}) If you change the signature of method (type or number of parameters), you make method overloading, so you can change the return type but it's not possible to make overloading changing just the return type - number or type of parameters must to change on overloading. I recomend this article for more information: https://docs.oracle.com/javase/tutorial/java/IandI/override.html
26th Apr 2019, 4:45 AM
Rafael S Valle
Rafael S Valle - avatar
+ 3
You can try it out. As a programmer it is important to try it out and see what happens.
20th Apr 2019, 7:06 AM
Dragonxiv
Dragonxiv - avatar