[Logo]
Forums Register Login
Overloading Signature
Which of the following statements are true?





a) Overridden methods have the same method name and signature

b) Overloaded methods have the same method name and signature

c) Overridden methods have the same method name and different signature

d) Overloaded methods have the same method name and different signature
My answers (a) and (d).
Can overloaded methods have same signatures??
Signature of overloaded method will include its name argument type and not its return type.Overloaded method means same method name and differrent arguments. If you change the argument the signature will also change ,am I right??
Yes, you are right. And 1 more thing. Even in JLS this is not specified clearly. The order of the arguments is also VERY IMPORTANT. For example
void m1(int i,float f) {}
void m1(float f,int i) {}
These 2 methods are NOT OVERRIDDEN. Instead they are OVERLOADED. Also note that when invoking
m1(10,10f); //Ok
m1(10f,10); //Ok
m1(10,10); //Compiler will shout!!! It is ambiguous.
regds
maha anna

[This message has been edited by maha anna (edited March 09, 2000).]
stupid question
does the method signature include the access modifier(public,private...)
No, thats not a stupid question at all, but a stupid answer is nope! Whats more i'm also too lazy to elaborate.
No, the signature does not include the access modifiers nor the return type. Only the name of the method, and the types, number and order of the arguments.
Can anybody give some tips on In which situation we may need to go for OVERRIDING or OVERLOADING considering I am new to OOP.
thanx in advance.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Oct 16, 2017 21:58:20.