• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

string quest

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which methods can be legally applied to a string object?
a) equals(object)
b) equals(String)
c) trim()
d) round()
e) toString()
According to me the answer is a,c & e
but the solution says a,b,c & e
please explain because threr is no method in the string class which takes a String as an argument.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
b is correct because String is subclass of Object..
String is automatically converted to Object type..
String s=new String();
Object o=new Object();
o=s; Valid .. so above answer b is also correct..

For more info refer to the following
API:
public boolean equals(Object anObject)
Compares this string to the specified object. The result is true if and only if the argument is
not null and is a String object that represents the same sequence of characters as this
object.
Overrides:
equals in class Object
Parameters:
anObject - the object to compare this String against.
Returns:
true if the String are equal; false otherwise.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Latif b is also correct

try this example
boolean b;
String s = "asdf";
String s1 = "asdf";
b = s1.equals(s);
here equals(String) is taking s as String Object and compare with another String object.

Means equals(String) is valid method for String .

reply
    Bookmark Topic Watch Topic
  • New Topic