W
W
WTFAYD2016-08-08 16:00:35
Java
WTFAYD, 2016-08-08 16:00:35

Why does the inner class need an object of the outer class?

Why does the inner class need an object of the outer class? Is it because the inner class has access to the fields and methods of the outer class?
Tell me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evhen, 2016-08-08
@WTFAYD

Not an object, but a reference, and if it's not a static inner class.
Yes, that's right, because you need access to the fields and methods of the outer class.
If you decompile the inner class, you can see that the compiler adds a parameter to the constructor - a reference to the outer class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question