Click to See Complete Forum and Search --> : Simple Question
Aslam
August 25th, 1999, 06:57 AM
What's wrong in following code,
class temp {
public static void main(String args[]) {
static int i=10;
}
}
Why can not i have a static variable in a static function?
August 25th, 1999, 08:34 AM
Static variables are associated with a class and not methods.A static variable is a single copy for a class and can be accessed using class name.A variable declared in a method has scope limited to the function and how is it possible to access a variable in a method using method name .I think this type of declaration hold good in C and not in Java(OOPS languages).
September 3rd, 1999, 03:03 PM
Why not just make the static variable a class variable (move it to the class declaration)? The effect will be the same, and it will be in the same namespace.
So you would have:
class temp {
private static int i=10;
public static void main(String args[]) {
}
}
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.