One 、 Internal class concept
The so-called inner class is to continue to define a class in a class , The advantage of inner classes is that they can easily access the private properties of outer classes , But inner classes are used more often in Android development .
DEMO: Define inner classes
The private properties of the outer class are accessed in the inner class , But inner class objects are created in outer classes , If you want to create it outside of the external class ? For example, can it be created in the main method ?
DEMO: Create inner class objects in the main method
The error is “Inner Not a type ”, So you can't create inner class objects directly outside the outer class , Because inner class objects depend on outer class objects , If you want to instantiate an internal class object, you need to instantiate an external class object first .
DEMO: Instantiate the external class object first
The above is the creation of an internal class object .
1、 The inner class can directly access the private properties of the outer class
2、 Inner class objects depend on the existence of outer class objects , If you want to get the inner class object, you need to instantiate the outer class object first .
There is a complete Java primary , Advanced corresponding learning routes and materials ！ Focus on java Development . Share java Basics 、 Knowledge of principle 、JavaWeb actual combat 、spring Family bucket 、 Design patterns 、 Distributed and interview materials 、 Open source project , Help developers grow ！
Welcome to WeChat official account. ： Code state Lord