Hi all, I have a doubt regarding constructor overloading. If I have a method with the following signature: public void amethod(int i,String s) Then the method public void Amethod(int i,String s) is an overloaded method or a different method. Please help.thanks.
Hi, I will be little bit clear. Original method is: public void amethod(int i,String s) which of the following are legal overloaded methods: A.public void Amethod(int i,String s) B.public void Amethod(String s,int i) Please help me.Thanks in advance.
hi santhi, about u r question. 1) constructors have no return types thus public void amethod() is not a constructor but public amethod() is a constructor 2) Java is case sensitive thus public void amethod() is definetly differnt than public void Amethod()
3) There is something called a Signature of a method. A signature of a method which is the parameter types, the sequence of the parameters and method name. This does not include the return type. the signature of public void Amethod(String s, int i) is definetly different from public void Amethod(int i, String s) u may ask why? this is because if it is not so how can the compiler resolve the parameters passed in this case public void Amethod(String a, int i, String b, int e)// I public void Amethod(String a, String b, int i, int e)//II now how will the compiler be able to resolve the fact that String a of II refers to String a of I and not String b of I. thus I and II are different methods with different signatures.
Hai santhi, This is not overloading.Overloading means having same method name but having different parameters list and it may have have different return types also.Givving method name as different is not overloading. I hope this may clear your doubt.OK. If not please reply where you are not following .OK. Bye.... VijayaLakshmi.M