aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes KB queston pg 5o1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "KB queston pg 5o1" Watch "KB queston pg 5o1" New topic
Author

KB queston pg 5o1

Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
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..


Thanks<br />Dinesh
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

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.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Yaroslav Ashurin
Greenhorn

Joined: Apr 25, 2008
Posts: 20

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.


SCJP 1.5
 
 
subject: KB queston pg 5o1