• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

String and StringBuffer overloaded methods

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Please explain:
In a class, one method with String argument, and another overloaded method with StringBuffer/StringBuilder Arguement are exists. How the compiler make the difference between them?

Thans in Advance.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by m ali:
Hi All,

Please explain:
In a class, one method with String argument, and another overloaded method with StringBuffer/StringBuilder Arguement are exists. How the compiler make the difference between them?

Thans in Advance.



Hi ali,

String, StringBuilder and StringBuffer are differnt classes. Compiler can tell which object is being passed. Based on that, it will select appropriate method.

hope this helps,
Raghav
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raghav Aggarwala:
...String, StringBuilder and StringBuffer are differnt classes...


Furthermore, none of these have a superclass/subclass relationship with each other. Each one is a direct subclass of Object.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,

what Marc wrote can be a bit misleading.
In overloaded methods, only the compile typy counts.
It doesn't matter, how the inheritance tree is.
If you have a class B extending A you can have an overloaded method for both A and B:

prints

A
B
X
A


Yours,
Bu.
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic