Inner or nested class example in Java

preview_player
Показать описание
In this video you will learn about how to create inner class or nested class in java
using a demo project
Below is the GitHub link to download source:
Рекомендации по теме
Комментарии
Автор

This breezes thru a few things that many beginners might be confused by.
1. You can never have an instance of the Inner class, also sometimes called a member inner class, without an instance of the Outer class. Of course, you show this, but it is something to be emphasized.
2. The OuterClass.InnerClass innerObj = new OuterClass().new InnerClass();
Is a bit tricky to understand. Here we are creating a new instance of OuterClass, keeping no explicit reference to it, but then using that to create an instance of the InnerClass using this very weird syntax. The InnerClass itself holds a reference to the outer class. Even once the syntax is mastered, this is a little bit of a complex situation.
There is no incorrect information in this video, but I find this pretty tricky. It might bear slower, or more careful discussion.

jvsnyc