• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can they be saved - HeadFirstJava Sharpen your pencil  RSS feed

 
Bart Boersma
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi CodeRanch,

I am currently reading the book HeadFirstJava and came across an exercise. The question is whether its serializable or not? If not, why not?

Object type,         Seriablizable?              
Object                Y/N
String                 Y/N
File                     Y/N
Date                   Y/N
OutputStream     Y/N
JFrame               Y/N
Integer               Y/N
System               Y/N

Currently I figured out that Object, string, file, date, JFrame and Integer are serializable. That would mean OutputStream and System are not, can you guys explain me why?

Cheers,

Bart

 
Igor Soudakevitch
Author
Ranch Hand
Posts: 38
7
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can offer the following short answer:
To be serializable, a class should implement the interface Serializable, and those two classes don't do that. Besides, System cannot be instantiated so there's no object...
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at the API documentation for many interfaces, it will show you a list of classes implementing that interface. Serializable doesn't show such a list, possibly because it would be too large to be of any use in the documentation. If you look at the documentation for those classes, or one randomly chosen from the same page I happened to be on, it says implemented interfaces, and you find that list includes Serializable.
What makes you think that java.lang.Object implements Serializable? Since every class is a subclass of it, that would mean that every class would implement Serializable, too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!