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 - ローランド

4

1 に答える 1

0

static int theint静的として宣言したことを確認してください。したがって、オブジェクトを使用してこの変数にアクセスする必要はありません。className.variable次のように を使用できます。

Charlie.theint;

クラスが他のクラスから見える場合、これは機能します。

于 2013-02-25T03:42:23.797 に答える