A
A
afna2015-01-29 12:04:08
Java
afna, 2015-01-29 12:04:08

What is the inner class for?

Can anyone please explain the following lines from the Java Philosophy book:

So the most compelling reason to use inner classes is this:
Each inner class is able to independently inherit a particular implementation. Thus, the inner class is not restricted from being inherited in situations where the outer class already inherits the implementation

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander P, 2015-01-29
@sulik93

In Java, multiple inheritance is not possible (this text is about implementation, so interfaces do not count), so an external class can be a descendant of only one class (let's call it A). But if you need to reuse the behavior of some other ancestor (let's call it B), then you need, accordingly, another descendant - its role will be performed by the inner class. And, being internal, it will also have access to all members of the outer class, which will eventually allow it to use the capabilities of both A and B.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question