when i want to override a method within the subclass can i change the return type of it?if i change does it still mean i am overriding that method?and when override a method does the order of the parameters matter?
[code]
int myMethod(first_parameter,second_parameter)
{
}
[/code]
Three answers:
AnalProgrammer
2011-09-16 23:50:53 UTC
Check this link for the answer.
It is the method name and the number of and type of parameters that make up the method signature, not the return type.
So surely if you have a method with a different return type then it is a totally different method and the name should therefore be different.
Have fun.
Vaibhav
2011-09-17 03:42:28 UTC
You can change the return type because it does not matter
but you can not change order of parameters because then your method becomes an overloaded version of superclass method
Kamal Nayan
2011-09-17 00:26:50 UTC
while over-riding a method, signatures of method must exactly match.
That means you cant change its return type or name or parameter list. However you can change the method body.
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.