|
-
August 25th, 1999, 06:57 AM
#1
Simple Question
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
#2
Re: Simple Question
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
#3
Re: Simple Question
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[]) {
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|