aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "string quest" Watch "string quest" New topic
Author

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
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.
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: string quest