aspose file tools*
The moose likes Beginning Java and the fly likes array scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "array scope" Watch "array scope" New topic
Author

array scope

John Kirvan
Greenhorn

Joined: Feb 01, 2005
Posts: 12
How do you know what the scope of an array is? Can it be accessed from anywhere if its in the main method
Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
First answer: depends on where the array is declared.
Second answer: no
John Kirvan
Greenhorn

Joined: Feb 01, 2005
Posts: 12
how do you make an array available for all classes within your program.
Hentay Duke
Ranch Hand

Joined: Oct 27, 2004
Posts: 198
Declare it outside a method. Anything declared inside a method has scope limited to that method. This includes the main method which is just another method.

Here's a small example



Hope this helps!
John Kirvan
Greenhorn

Joined: Feb 01, 2005
Posts: 12
Thanks, knowing an array within a method only can be used within that method should help a lot logically. My professor has the array initilized within a method and I don't think were allowed to change that part of the code, but i'll probably think of something. Thanks again
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Scoping rules are the same for all variables. Arrays are not special in this context.

Layne


Java API Documentation
The Java Tutorial
Hung Yee
Greenhorn

Joined: Dec 22, 2004
Posts: 18
FYI: Sun has a tutorial that talks about a variable's scope that might interest you:

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/scope.html
 
 
subject: array scope