Casting a Person object to string giving class cast exception
<p>I have made a class of Person object which is implementing Serializable interface, which contains fname,lname,phone,address in its constructor, and i am storing the objects of this class in ".dat" file by streams, i wanna display these contacts on GUI so when i try to cast person to a string it gives ClassCastException, i will be thankful if someone will help.</p>

<p>this is a constructor:</p>

<pre><code>public Person(String fName, String lName, String add, String ph) {
    //super();
    this.fName = fName;
    this.lName = lName;
    this.add = add;
    this.ph = ph;
}  
</code></pre>

<p>and this is GUI class code:</p>

<pre><code>public void windowOpened(WindowEvent e) {

    FileInputStream fis;
    ObjectInputStream ois;

    try {
        fis = new FileInputStream("person.dat");
        ois = new ObjectInputStream(fis);
        Person p = (Person) ois.readObject();
        String obj = (String) p.toString(); // giving error at this line
        StringTokenizer str = new StringTokenizer(obj, " ");

        textField.setText(str.nextToken());
        textField_3.setText(str.nextToken());
        textArea.setText(str.nextToken());
        // System.out.println(p);
        ois.close();
        fis.close();
    } catch (Exception ee) {
        System.out.println("Cannot Read File" + ee.getMessage());
        ee.printStackTrace();
    }
}
</code></pre>
