Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about static variable...

 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

it prints: 1 1
connectionCounter is a static variable. So why am I able to modify this variable in a non static method?
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andres
You can access a static variable from a non-static method but the vice versa is not possible. That is you can not access a non-static variable from a static method.
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ooppss.. i need a break
thx
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic