File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes unable to define static variable inside method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "unable to define static variable inside method" Watch "unable to define static variable inside method" New topic
Author

unable to define static variable inside method

Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
Hi There,
Why I am unable to define static variable inside a method, even under
static method. See the example below.

[ October 20, 2003: Message edited by: Sivanantham kandan ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Yes, that's right. You can't define a static variable inside a method, only at class scope. That's how Java works.
Can you explain why you want to do this?


[Jess in Action][AskingGoodQuestions]
Derek Baker
Ranch Hand

Joined: May 23, 2003
Posts: 46
The point of a static member (variable or method) is that it belongs to the whole class. It therefore does not make sense to define it inside a method.
Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
Thanks to you all.
Hi Derek,
It makes sense. Got it.
Hi Ernest,
I have no application in mind. That was just like that,
I was happen to try.
thanks
siva
x38020
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: unable to define static variable inside method