This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: question about static variable...
 
Similar Threads
How tp print Hello World on the screen many times without using any loops!!?
why dont...
Doubt in the output of this program.
about static variable question
Need Explanation of unpredicted output even if methods are synchronized