Accessing instance methods that are two objects deep in Java
<p>Say I have a class, <code>Bobject</code> with an instance variable and method to retrieve it:</p>

<pre><code>public class Bobject {
    private int bInstVar;

    public Bobject() {
        bInstVar = 1;
    }

    getBInstVar() {
        return bInstVar;
    } 
}
</code></pre>

<p>If I create a class <code>Cobject</code> representing an object that is an array of <code>Bobject</code> like so:</p>

<pre><code>public class Cobject {
    public Bobject[] cInstVar;

    public Cobject() {
        cInstVar = new Bobject[2]; //arbitrary array size for simplicity of the question
        for (i = 0; i &lt;= 2; i++;) {
            cInstVar[i] = new Bobject(); 
        }
    }
}
</code></pre>

<p>If I have a main program that creates a <code>Cobject</code> and attempts to access methods of the references to the <code>Bobjects</code> stored in each element, I find that I have to first access the <code>Cobject</code> instance variable, <code>cInstVar</code>. This means cInstVar has to be <code>public</code> for main() to get at it without a method if main is outside of the package or class. </p>

<p>My question is, is there a way around doing this:? </p>

<pre><code>Cobject c = new Cobject;
    c.cObject1[0].getBInstVar();
</code></pre>

<p>Instead, I want to have an object that is an array of another class and get to that classes instance methods easier like so:</p>

<pre><code>Cobject c = new Cobject;
    c.getBInstVar(); // error says 'array required, but Cobject found'
</code></pre>

<p>I'm still pretty new to Java (and stackExchange) so please forgive me if anything I've presented is unclear. Thanks in advance!</p>