Frank Poupard wrote:Hello, this is probably a basic question but I have some issue with the following classe : I would like to re-use the variable field2d which is an array of char (declared in the main method of the class Project) in another class.
For example, I would like to iterate over this array but I got the following error : « field cannot be resolved to a variable » in the for loop. What I have overlooked? thanks!
Directly? Well, you can't. Local variables are ... well ... local to the method where they are declared. However, you have a few options as alternatives... One. You can use a different type of variable. One with a scope that is accessible by both methods, such as instance or static variables. Two. You can also pass the instances around, such as using method parameters and/or returns. This second case will declare different local variables, but the different references can be made to point to the same instances.
Henry