Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question about static variable... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question about static variable..." Watch "question about static variable..." New topic
Author

question about static variable...

Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561

it prints: 1 1
connectionCounter is a static variable. So why am I able to modify this variable in a non static method?


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
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

Joined: Nov 27, 2001
Posts: 1561
ooppss.. i need a break
thx
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about static variable...