I wrote the following code using ObjectOutputStream:
class ClassToTestOutputStream implements Serializable{
    int a;
    String b;
    public ClassToTestOutputStream(){
        a=10;
        b="Deepak";
    }
    public String toString() {
        String s = ""+a+" "+b;
        return s;
    }
}
public class UsingOutputStreams {
    ClassToTestOutputStream ref;
    private ObjectOutputStream oos;
    public UsingOutputStreams(){
    try {
         oos = new ObjectOutputStream(System.out);
    } catch (IOException e) {
        e.printStackTrace();
    }
    ref = new ClassToTestOutputStream();
}
public void writeOnScreen(){
    try {
        System.out.println("Writing on Screen");
        oos.writeObject(ref);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
    public static void main(String[] args) {
        UsingOutputStreams obj = new UsingOutputStreams();
        obj.writeOnScreen();
    } 
}
And I got answer :
�� Writing on Screen
sr ClassToTestOutputStream����S��M I aL bt Ljava/lang/String;xp
t Deepak
Please help me figure out why such output gets printed.
 
     
    