• Post Reply Bookmark Topic Watch Topic
  • New Topic

instance variables  RSS feed

 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Please see 2 codes below from HFJ




 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not understanding what lines 6,9,10 from the second program does. Any help would be appreciated.

thanks
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code is for illustration purposes only. It's showing you that objects can have variables (states) and methods (behaviors).

Drumkit d has an instance variable of snare. The code above sets it to false.

This code tests d's snare variable to see if it's true. It isn't, so playSnare() is never executed.

In "real life", you would create a getter and setter for d.snare.
 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much for your explanation. much appreciated.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . .. . .
Did they really use == true? You shouldn't. you should write:-
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!