次の2つのネストされたクラスがあると考えてください。
public class Foo {
public class Bar {
}
}
そして、私の目標は、クラスのインスタンスを作成することBar
です。私はそれを次の方法でやろうとしました:
// Method one
Foo fooInstance = new Foo();
Foo.Bar barInstance = new fooInstance.Bar // fooInstance cannot be resolved to a type
// Method two
Foo.Bar barInstance = new Foo.Bar(); // No enclosing instance of type Foo is accessible
どんな助けでも大歓迎です、私は立ち往生しています。お気づきかもしれませんが、私はJavaの初心者です。これは、これを宿題の質問にすることはありません(実際のところ、そうではありません)。
Bar
クラスのインスタンスを作成するにはどうすればよいですか?できれば同じFoo
インスタンスで。