aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serialization topic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Serialization topic" Watch "Serialization topic" New topic
Author

Serialization topic

Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97


Why the above code giving runtimeException??
I thought Room is a subclass of Hotel so both Room and Hotel are Serialized.

Please,correct me if i am wrong.
S Ali
Ranch Hand

Joined: Aug 23, 2009
Posts: 129
The exception you got has nothing to do with serialization . A StackOverFlowError is thrown because what happend is that when you created an instance of Hotel it created an instance of Room which extends Hotel so hotel variables had to be initialized again including an instance of room and so on to infinity. The stack couldn't take it anymore and ran out of memory which caused JVM to crash and throw this error .


SCJP 6
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
Also in an OO design, it doesn't make sense to have an instance of a subclass.
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
Thank you both...
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Leandro Coutinho wrote:Also in an OO design, it doesn't make sense to have an instance of a subclass.


What do you mean by that?

For instance, the Java Collections Framework has an abstract class named AbstractCollection. All lists and sets inherit from it Therefore, ArryaList, is a subclass of AbstractCollection. And according to your statement it would not make sense to have an instance of ArrayList (which is a subclass) or AbstractCollection.

So, can you elaborate more on your statement? Because it sounds wrong to me so far.
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
Edwin Dalorzo wrote:
Leandro Coutinho wrote:Also in an OO design, it doesn't make sense to have an instance of a subclass.


What do you mean by that?

For instance, the Java Collections Framework has an abstract class named AbstractCollection. All lists and sets inherit from it Therefore, ArryaList, is a subclass of AbstractCollection. And according to your statement it would not make sense to have an instance of ArrayList (which is a subclass) or AbstractCollection.

So, can you elaborate more on your statement? Because it sounds wrong to me so far.

lol sorry
I meant: It doesn't make sense a superclass to have an instance of one of its subclasses.
Eg: It doesn't make sense the class Car to have an instance of Ferrari.

Well, that's what I think so. Is it clear now?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Serialization topic