• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialization problem  RSS feed

 
Shaan Royal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone one explain this program . . . . ? y is it going thru an infinite loop like a sea of erorrs or exceptions . . . ?

import java.io.*;
class Forest implements Serializable
{
private Tree tree = new Tree();
public static void main(String [] args)
{
Forest f = new Forest();
try
{
FileOutputStream fs = new FileOutputStream("Forest.ser");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(f); os.close();
} catch (Exception ex) { ex.printStackTrace(); }
}
}
class Tree extends Forest { }
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hint: A Forest HAS-A Tree. And a Tree IS-A Forest.... is this what you intended?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!