Consider that I have the two following nested classes:
public class Foo {
public class Bar {
}
}
And my goal is to create an instance of class Bar. I've tried to do it the following ways:
// 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
Any help would be highly appreciated, I'm stuck. As you might notice, I'm a Java-beginner: which doesn't automatically make this a homework question (as a matter of fact - it isn't).
How can one create an instance of the Bar class? Preferably with the same Foo instance.