I think there'a fairly major misunderstanding going on here. To simplify your question a little, you say:
<pre>
class A
{
public int c = 6;
}
class B
{
int a1 = c;
}
</pre>
This still won't compile, but all the non-essential bits have been removed.
Now. In
Java, everything belongs to a class. There are no "global variables" or functions which exist on their own. You seem to have understood this, which is good. However, there are two ways for something such as a variable to belong to a class. It can be either part of an object created from the class, or part of the class itself. Everything is assumed to be part of an object, unless the "static" keyword is used to indicate that it is part of the class.
Here's an example:
<pre>
class A
{
public static int x; // only one of it, part of the class
public int y; // each object has a different copy
public void show()
{
System.out.println("x is " + x + ", y is " + y);
}
}
</pre>
To access something which is part of an object, you need an object, and you need to say which object you are referring to. The easiest way to get an object is to call "new":
<pre>
A a = new A();
</pre>
Once you have such an object, you can access any public variables and methods, for example:
<pre>
int result = a.y;
a.show();
</pre>
Anything which is declared "static" can also be accessed through the class name:
<pre>
int another = A.x;
</pre>
So lets put all this together into a real compilable file. Cut and paste the following to see it work:
<pre>
class A
{
public static int shared = 12;
public int different = 13;
public void show(String name)
{
System.out.println(name + ": shared is " + shared + ", different is " + different);
}
}
public class B
{
public static void main(String[] args)
{
A a1 = new A();
A a2 = new A();
System.out.println("initial values");
a1.show("a1");
a2.show("a2");
System.out.println("change one object");
a1.different = 26;
a1.show("a1");
a2.show("a2");
System.out.println("change the shared value");
A.shared = 99;
a1.show("a1");
a2.show("a2");
System.out.println("change it a different way");
a2.shared = 75;
a1.show("a1");
a2.show("a2");
}
}</pre>
To summarise. In your example you are trying to access a variable which is part of an object, but you don't say which object to look at - which is why it won't compile. The choices you have to make it work are (a) mark it as "static" and use "A.c" to access it, or (b) create an object of class A and use that to access it.
I hope this has helped.