This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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.