| Author |
non static variable in static class
|
mari maris
Greenhorn
Joined: Mar 22, 2008
Posts: 7
|
|
normally a static method can only access static variable..but in public static void main() the main class access non static variable..how is it so.. class one { public static void main(String args[]) { int a=5;//non static variable int b=3;// non static variable int c=a+b; System.out.println(c); } }
|
 |
Marco Ehrentreich
best scout
Bartender
Joined: Mar 07, 2007
Posts: 1220
|
|
Hi! It's true that a static method cannot access non-static class member variables. But in your example a, b and c aren't such member variables. Instead they are local variables which are always accessible (only) within the method in which they are declared! It wouldn't make sense if you could just declare local variables but couldn't use them Marco
|
 |
 |
|
|
subject: non static variable in static class
|
|
|