Make 'em private members.
http://docs.oracle.com/javase/tutorial/java/javaOO/variables.html[
^]
Extended Answer:
public class MyProgram
{
private ObjectA oObjectA = new ObjectA();
private ObjectB oObjectB = new ObjectB();
public MyProgram()
{
System.out.println(oObjectA.y);
System.out.println(oObjectB.z);
System.out.println(oObjectB.getX());
}
public static void main(String[] args)
{
new MyProgram();
}
private class ObjectA
{
private int x = 10;
public int y = 20;
protected int z = 30;
public int getX(){
return x;
}
}
private class ObjectB extends ObjectA
{
}
}
Please understand the basics behind this.
Please read behind that link, there is much more for you to learn.
And your teacher will figure that this code is not yours.