0

When would an inner class be used and not an extended class?

What would be a simple example of an inner class being used. Why not just use extend? Some have already explained the difference between inner and extend but an example would help me understand it better.

2nd Apr 2017, 7:43 PM
Evan T Espey
Evan T Espey - avatar
2 Réponses
+ 2
When You use extension it's like You would wrote extended class again but this time with additional fields and methods (those in extending class). By using inner class instead, You simply have a class intouchable from outside of encapsulating one. Differences - You can declare" public class2 extends 2 {}" - but class2{ class1} means hidden class 1 You can so use a nested class but it's better to read java oracle essentials for the right view.
2nd Apr 2017, 7:55 PM
Michał Bujakowski
Michał Bujakowski - avatar
+ 1
i guess you would use inner class when you only need that inner class for only one other class
2nd Apr 2017, 7:59 PM
Edward