meeta gaur wrote:String class implements CharSequence interface then why can't it hold returned object ?
Because CharBuffer, Segment, StringBuffer and StringBuilder also implement CharSequence and so the compiler doesn't know that it will definitely be a String that is returned.
You can override this by putting an explicit cast in your code
This says to the compiler - I know that the object returned from the method could be something other than a String, but I'm telling you it will be a String
Of course, if, at run time, something other than a String is returned, you will get a ClassCastException.