Hi I have the following classes:

Home.java
Away.java
Other.java

In Home.java i have a declaration like:

private Away away;
private Other other;
other= new Other(AN ARRAY);
away = new Away(AN ARRAY , other);
//where AN ARRAY is just an array, and other

I then have code to pass AN ARRAY, other to Away.java

Now in Away.java I have:

private Other other;
public Away(AN ARRAY, Other panel)

I know that to access the array that was passed from anywhere else in the class Away, i can do the following in the constructor:

this.AN ARRAY= AN ARRAY .

What can i do to access the methods of Other from another location except the constructor of Away.java ? I know that to access the methods from the constructor i can do

panel. METHOD_OF_OTHER.JAVA()

However what do i need to do to be able to access the methods of Other.java from other locations (like Button listeners or other methods) in the class Away.java?

in the constructor of away, save the instance of other. in the same way as away, you can have this.other, and access its methods like that.

You need to have a member variable of type Other in your Array class, then in the constructor you initialize it to whatever is being passed to you. And then you make use of this variable to access methods of Other class.

Note : The methods of the Other class that you need to access from Away.java should be made public or have a package scope and Away and Other should share the same package.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.