• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialization - Headfirst pg 444 chap 14  RSS feed

 
Elim Banda
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm finding this program a bit confusing. I understand how the serialization works but towards the end there is a getType method used for printing. Where did the program get this method from how does it know what type the object is? please see attachment.

Capture1.1.JPG
[Thumbnail for Capture1.1.JPG]
 
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
Elim Banda wrote:Where did the program get this method from how does it know what type the object is?


Well, there should be a GameCharacter class listed somewhere else in the book that is not shown here.  And once you find the source for that class, then there should be that method. Otherwise, the code won't compile.

Also, I would be hesitant to use the word "program" here. In the context used, it implies the whole program, and you only shown one class of it.

Henry
 
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
It looks like you answered your own question in your other topic...

https://coderanch.com/t/674561/java/Java-serialization-Headfirst-pg

See the GameCharacter class in your other topic. And see the method that it uses.

Henry
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Elim Banda
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im having trouble understanding this program. I cant use it can somebody give me a hint. How do I get it to print the GameCharacter proprties. I tried instantiating new object but was not able to. Can anybody help ?

 
Liutauras Vilda
Sheriff
Posts: 4928
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags when posting the code, not the quote. Or better if you're quoting the code - use both.
1. Quote code (quote tags)
2. Explicitly select code within quote tags and click Code tag

Before click submit, please check how that looks like.
Elim Banda wrote:I tried instantiating new object but was not able to.
Please show us what have you tried.
 
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
It looks like you took two classes from the same "program". And create two topics, one for each class, asking about stuff done by the other class.

See your other topic on how to instantiate the GameCharacter class.

https://coderanch.com/t/674560/java/Serialization-Headfirst-pg-chap


And also, there is no reason to have two topics, so let's lock this one. [Edit: topics were merged]

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