File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

KB queston pg 5o1

 
Dinesh Tahiliani
Ranch Hand
Posts: 486
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Keyboard
{
}

class Computes extends Keyboard implements Serialoizable
{
KeyBoard k = new keyboard();
public static void main(String a[])
{
Computer c = new Computer();
c.storeit();
}

void storeit()
{
try
{
ObjectOutputStream os = new ObjectOutputStream( new FileOutputStream("myfile"));
os. writeObject(c);
os.close();

System.out.println("dine");

}
catch(Exception x)
{
System.out.println("exc");

}
}

Answer - exc

Can anyone please explain the output..
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the error you get ?

From a glance it appears that the entire object graph is not serializable and that is why an exception is thrown.
 
Yaroslav Ashurin
Greenhorn
Posts: 22
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Dinesh,
The Keyboard class does not implement Serializable interface; Computer class has-a Keyboard, and Runtime error happens when you attempt to serialize the c object. Declare Keyboard k as transient, that should help.

Regards,
Yaroslav.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic