When you've got two or potentially more methods in one class and you want to use array information from one method in the other, how can we do this?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
When you've got two or potentially more methods in one class and you want to use array information from one method in the other, how can we do this?
Make the array a class variable so all methods in the class can access it.
If you don't understand my answer, don't ignore it, ask a question.
Or a non-static field. You can learn more about Java's variables here.
Does the term: class variable mean static? How is a variable defined at the class level vs inside a method described? I've been using the terms: class variable and method variable to mean the scope where the variable is defined.
I guess I need to change to: instance variable and local variable.
If you don't understand my answer, don't ignore it, ask a question.
Yes.Does the term: class variable mean static?
@maths94: My suggestion assumes (or hopes) that your designs are evolving from the beginner's stage that places almost all logic in the main() method that calls a few static methods. If you're not sure what I mean, post some code that illustrates what you're trying to do.
Generally non-static variables are called instance variables.
Improving the world one idiot at a time!