A
A
Andrey Kulagin2020-04-15 14:03:38
Java
Andrey Kulagin, 2020-04-15 14:03:38

Does the outer class have access to all members of the inner class?

I am reading metanit theory on inner classes, and it says that the outer class has access to all members of the inner class, including fields and methods with the private modifier ( https://metanit.com/java/tutorial/3.12.php ) at the same time, according to Schildt, "an inner class has access to all elements of its outer class, but not vice versa. Members of the inner class are available only in the scope of the inner class and cannot be used by the outer class", that is, a clear contradiction. How is it right anyway?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2020-04-15
@fapsi

The way it is

The inner class has access to all fields of the outer class, including those that are private with the private modifier. Similarly, the outer class has access to all members of the inner class, including fields and methods with the private modifier.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question