To answer your original question "how can we convert the type of the object using type casting": You cannot.
Casting is not a way to convert objects from one type to another. Since String and StringBuffer are two different (unrelated via inheritance) classes, there is no way to convert a String to a StringBuffer (or vice versa) via casting.
The only thing that casting is, is a way to tell the compiler: "look, I have a variable that refers to an object of type X here, but the object is really of type Y, so I want you to treat it as if it's an Y". But this does not automatically somehow convert an X to an Y - if the object really isn't an Y, you will get a ClassCastException at runtime.
For example, suppose that you have a method that for some reason has Object as its return type:
Suppose that you want to call this:
Now result is of type Object, but you know that the method really returns a String. You can cast the result to String:
Now result is a String, despite that the method says that it returns Object.