• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

overloaded methods

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
sadas dsdasd
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like none...
They have to have same name(case sensitive) to be overloaded.
Isn't It Java Gurus?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

HOpe i have clarified adequately.
Regds.
Rahul.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic