• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serializeable  RSS feed

 
vibhas karn
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody i got some doubt regarding a code from Kethy and Seirra baseed
on Serializable.....
I put the doubt part in the comment of this following code assigning them number 1>>,2>>,3>>.. please anybody clear it... here is the code



[edit]Add code tags. CR[/edit]
[ September 05, 2008: Message edited by: Campbell Ritchie ]
 
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
1>> It says can not find symbol d.CollarSize() why ??;


Because a dog object doesn't have a method that returns the collar size -- as explained by the error message.

//2>> here it prints Collar@12b6551(which is address) why so why not content state;


Because the printing mechanism will convert it to a string before printing it, and the default toString() method gives the type and the indentity hashcode. How do you expect Java to know what valid "content state" is, when it is your code? If you want it, you have to override the toString() method.

d.getCollar().getCollarSize();//3>> why the order of invocation is like this way why not the reverse way...this is really not understood properly;


Can you explain why it is "really not understood properly"? It makes perfect sense to me. You are calling the collar() method on the dog object. This method returns an collar object, which you call the collar size method on. Maybe it is better understood, if you add parens....

(d.getCollar()).getCollarSize()

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
BTW, these questions have nothing to do with the title of your topic... but you probably already know that.

Henry
 
vibhas karn
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry I got my mistake and and no more problem on this code anymore
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!