• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot find symbol  RSS feed

 
Christian Somody
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand why it says that when I compile (it highlights the "mole" in the last line).

 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should read up on the concept of scope. any variable defined in a method disappears once it goes out of scope. basically, when you hit the closing brace for the block where the variable is defined.

In your code, you declare your Mole mole variable in each if/else block. as soon as you leave that block, the variable goes out of scope, and is lost. you probably want something like:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!