Why can't my Inner Class object use Outerclass method ?
dti.f() does not work. Why?
public class DotThis
public DotThis outer()
public Inner inner()
return new Inner();
public static void main(String args)
DotThis dt = new DotThis();
DotThis.Inner dti = dt.inner();
Re: Why can't my Inner Class object use Outerclass method ?
I will answer my own question:
Inner Classes have access to methods and instance variables of the outerclass, not the Objects you have.
So an Inner object can not call the f() method. But you can add a ff() method, that calls the f() method in the DotThis class, even if it was private.
But you must know this as well:
in your ff() method, you will have a secret Argument: DotThis.this , not a plain this. So you are still calling the f() method of the outer object.