• Post Reply Bookmark Topic Watch Topic
  • New Topic

question about scope of variable.  RSS feed

 
Serhat Duygun
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a practice book that I bought yesterday, before I got the IZO 808; there is one question but doesn't make any sense to me, I typed the code into the NetBeans but it has not been compiled. but book answer sheet says, yes there is nothing wrong with the code and result would be "31" please take look.



 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that code's invalid. The main() method is static, and it tries to access the tomorrow field which is not static.

If you changed line 9 so it read int today = 20; study.tomorrow = 40; the application would print "61".
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On line 9, change first semi colon to comma and you'll get 31.
 
Serhat Duygun
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:On line 9, change first semi colon to comma and you'll get 31.
Thanks now it makes sense
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!