Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question from Marcus Green

 
aishwarya mathur
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I'am going wrong somewhere,u may find it simple, here in the below code, as method <amethod> is non-static ,is it ok if we try to access variable j which is static.

 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes its ok.
its only static methods that cant access instance varibles, instance methods can access static veraibles.
 
Netty poestel
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I think the crux is one can't access non-static var. from within a static method.
the vice -versa is not true.
HTH
 
Kosh Shah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the output for the above code is:
10, and 40. Right?

Correct me if I am wrong!

Cheers,
Kosh!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic