0
我想知道是否有人可以讓我知道如何從我在主(小程序)類中創建的對象從我的主(小程序)類訪問對象。來源可能會澄清一些事情。通常我會用存取但這是爲了簡單起見從內部類訪問父級小程序
public class Bravo {
int copyint;
Bravo() {
// Here I want to access the targetobj's theint from here
copyint = targetobj.theint; // I belive this doesn't work
}
}
public class Charlie {
static int theint;
Charlie() {
theint = 7;
}
}
public class alpha extends JApplet {
public void init() {
createApp();
}
public void createApp() {
Charlie targetobj = new Charlie();
Bravo askingobj = new Bravo();
}
}
TYIA -Roland
_I相信這不工作_當你嘗試編譯時發生了什麼? – 2013-02-25 03:40:31
這是我的頭頂,但我真的懷疑這將在它的現狀 – 2013-02-25 03:41:29
你可以看到我的答案在下面,這應該工作。 – 2013-02-25 03:43:00