File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static variables and scoping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static variables and scoping" Watch "Static variables and scoping" New topic

Static variables and scoping

John Lincoln
Ranch Hand

Joined: Feb 11, 2003
Posts: 192
Can you same variable name for member variable and for variables in the method ? Is this because instance variables are on heap and local variables on stack ?

System.out.println(this.i); in the below code prints "10",which shows that static variable has been re-assigned.

How to tackle these type of questions

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
Yes you can. This is called shadowing.
I agree. Here's the link:
subject: Static variables and scoping
It's not a secret anymore!