Definition of Nested Classes
Nested Classes:
- Classes declared inside another class.
- Introduced from Java 1.1; were not available in previous versions.
Scope:
- The nested class cannot exist independently of the outer class.
- The scope is limited to the containing class.
- 2. Types of Nested Classes
Nested Classes:
- Can be declared as static or not.
- Internal Classes: The focus of the book, non-static, have direct access to variables and methods of the external class.
- 3. Use of Internal Classes
Purpose:
- Provide services that are used only by the external class.
Example:
- An inner class Inner is used to calculate the minimum, maximum and average of an array contained in the outer class Outer.
Outer.java
LocalClassDemo
The above is the detailed content of Introduction to nested and inner classes. For more information, please follow other related articles on the PHP Chinese website!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn