How can I add objects to a class array in Java? -


i'm hoping can me this, i've been puzzling on few hours , can't figure out. seems real easy thing do. ok, here goes...

i have class, class a. 1 of class a’s (private) instance variables array of objects of another, related class (class b).

in static method of class have created several objects of class b. need add these objects class a’s instance variable array.

i cannot use this directly access instance variable trapped in static class.

how can add newly created objects of class b class a’s instance variable array, in formal sense of course.

hope makes sense , thanks!

you're there. say, array instance variable of class a. means it's accessible when have instance of class a. need this:

a = new a(); // object system.out.println(a.arrayofb.length); // access a's array (but see note) 

note: code above simplest way this. however, shouldn't access array a.arrayofb directly. instead, should define method in class called getarray() return array. java standard practice.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -