File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes string quest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "string quest" Watch "string quest" New topic

string quest

Abdul Latif
Ranch Hand

Joined: Jul 18, 2001
Posts: 89
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.
suresh seeram
Ranch Hand

Joined: Oct 06, 2001
Posts: 42
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
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
equals in class Object
anObject - the object to compare this String against.
true if the String are equal; false otherwise.
Mr Iftikhar
Ranch Hand

Joined: Oct 12, 2001
Posts: 39
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 .

java language
I agree. Here's the link:
subject: string quest
It's not a secret anymore!