Objects can be created anywhere, but they can only be accessed from within the scope of which they were created. If you create a local object in a function then its scope is only as long as the function is running. If you create an object as a private data member for a class then its scope is only for that class. But you can get around that by creating accessor functions in your classes that allow you to get copies of the private data members.
Ex.
Class A
{
public static void main(
String args[])
{
B object = new B();
System.out.println("" + i); //doesn't work because you don't have
//access to i
}
}
Class B
{
private int i = 5;
B() //constructor
{
}
}
But,
Class A
{
public static void main(String args[])
{
B object = new B();
System.out.println("" + object.getI()); //works becuase the getI()
//function returns a copy of the
//value i
}
}
Class B
{
private int i = 5;
B() //constructor
{
}
public int getI()
{
return i;
}
}
I believe this is what you are trying to do, although my examples are in much simpler terms.