我是一個初學者,所以請非常特別。無論如何,我在這裏有三個代碼類,我想從c-b訪問數據,然後b-a E.g.從其他類訪問數據
class GoobyPls {
{
private int CHealth = 20;
private int MHealth = 20;
private int CAgility = 10;
private int MAgility = 10;
private int CDefence = 5;
private int MDefence = 5;
}
}
class Stats {
public static void foo() {
string Health = CHealth + "/" + MHealth ;
string Agility = CAgility + "/" + MAgility;
string Defence = CDefence + "/" + MDefence;
}
}
class ViewStats {
public static void foo() {
System.out.println("Health");
System.out.println(Health);
System.out.println(" ");
System.out.println("Agility");
System.out.println(Agility);
System.out.println(" ");
System.out.println("Defence");
System.out.println(Defence);
System.out.println(" ");
}
}
所以GoobyPls
是a
,Stats
是b
和ViewStats
是c
還我不能把它們都放在一個類,因爲終究會有一個修飾類編輯CHealth
,MHealth
等
這是[一個很好的開始](http://docs.oracle.com/javase/tutorial/java/javaOO/classes.html) –
此外,堅持[java命名約定](http:// java .about.com/OD/javasyntax /一個/ nameconventions.htm)。 – predi
感謝這看起來不錯 – user2687097