aspose file tools*
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 JavaScript Promises Essentials this week in the JavaScript 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
 
Consider Paul's rocket mass heater.
 
subject: question about static variable...