• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serilizable Parent/Child classes  RSS feed

 
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Parent class is Serializable, then Child class should be Serializable classs ?
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say 'yes', since a child IS-A parent.
 
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, (Child inherits Parent...? )
 
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
I think this question needs a bit more qualification...

If the question is referring to the Serializable marker interface, then yes, a subclass IS-A superclass, and hence, will also be IS-A Serializable too.

However, if the question is referring to an object actually being serializable, then maybe not, as it is possible for a subclass to provide readObject() and writeObject() methods, that thows a NotSerializableException.

Henry
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
However, if the question is referring to an object actually being serializable, then maybe not, as it is possible for a subclass to provide readObject() and writeObject() methods, that thows a NotSerializableException.

Henry


Henry, I couldn't get this point, Please explain further.

The readObject() method come from ObjectInputStream class, then?
 
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
Abimaran Kugathasan wrote:
Henry, I couldn't get this point, Please explain further.

The readObject() method come from ObjectInputStream class, then?


A good place to start is the Sun tutorial on serialization...

http://java.sun.com/developer/technicalArticles/Programming/serialization/

from it, you will see that there are ways to change the default serialization mechanism -- including being able to disable it.

Henry
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry, Will see what's going around....
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great article Henry... all the concepts cleared in 10 min... thanks...

just 1 ques... i did not understand this part in the article...
Just as before, though, there is no difference in how a class that implements Externalizable is used. Just call writeObject() or readObject and, voila, those externalizable methods will be called automatically


why are we calling writeObject and readObject when the Externalizable has readExternal and writeExternal methods???
 
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
tushar bhasme wrote:great article Henry... all the concepts cleared in 10 min... thanks...

just 1 ques... i did not understand this part in the article...
Just as before, though, there is no difference in how a class that implements Externalizable is used. Just call writeObject() or readObject and, voila, those externalizable methods will be called automatically


why are we calling writeObject and readObject when the Externalizable has readExternal and writeExternal methods???



I think you mis-interpreted that statement. That statement was talking about the readObject() and writeObject() methods of the object streams. The object streams don't have the readExternal() and writeExternal() methods, even when dealing with Externalizable objects.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!