Accessing instance outside of creation method
This is my first post. Please forgive me if this sounds ridiculous; I've scoured forums, tutorials and even textbooks, and I think my brain has Java-shaped holes in it because I can't figure this out. This is my problem:
How can I access an instance outside of the method that creates it (ie, access it in the main method in my example below)? Is it possible? I'm guessing it's a question of scope, but beyond that I'm at a loss.
Here is a simple example of what I mean:
Also, how could I access testperson, and its methods, in other non-main methods?
public static void main(String args)
String gender = "Male";
/*This doesn't work. What can I do to access testperson here?*/
public static void testy1(String gender)
Male testperson = new Male();
testperson.setMale("Test Subject Male");
else if (gender.equals("Female"))
Female testperson = new Female();
testperson.setFemale("Test Subject Female");
Help very much appreciated.