A question: in the following code, taken from SB6 Chapter 8 Self Test, I understand how to access the enclosing class method drive() from the inner class constructor and the initializer block.
but if I make a new instance of the enclosing class from within the inner class, I'm confused as to why I can't call the same method using that reference.
It will work if you call it from some block or method. Whether its an inner class or whatever you cannot call methods in a class where you can make only declarations or define methods.
I have added a works method and called c.drive() from there.
Joined: Jan 09, 2010
What I mean is you cannot do this -
B bb = new B();
bb.go(); // THIS IS WRONG
subject: Accessing enclosing class method from inner class