• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serialization topic

 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also in an OO design, it doesn't make sense to have an instance of a subclass.
 
Chandana Garlapati
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both...
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic