search
HomeJavaJavaBaseWhat are inner classes in java

What are inner classes in java

Nov 11, 2019 pm 04:58 PM
javainner class

What are inner classes in java

What is an inner class

A class inside a class is called an inner class.

Inner classes can be well hidden. Generally, non-inner classes are not allowed to have private and protected permissions, but inner classes can. The inner class has access to all elements of the outer class.

Internal class classification:

Internal classes can be divided into: instance internal classes, static internal classes and member internal classes. Each internal class has its specific Features.

If class B is defined in class A, then class B is an inner class, also called a nested class. Relatively speaking, class A is an outer class. If there are multiple levels of nesting, such as class A with inner class B, and class B with inner class C, then the outermost class is usually called the top-level class (or top-level class).

Internal classes can also be divided into various forms, which are very similar to variables, as shown in Figure 1:

What are inner classes in java

Features of internal classes:

1. The internal class is still an independent class. After compilation, the internal class will be compiled into an independent .class file, but it will be preceded by the class name of the external class and the $ symbol.

2. Internal classes cannot be accessed in ordinary ways. The inner class is a member of the outer class, so the inner class can freely access the member variables of the outer class, whether private or not.

3. If the inner class is declared static, you cannot access the member variables of the outer class casually. You can still only access the static member variables of the outer class.

Recommended tutorial: Java tutorial

The above is the detailed content of What are inner classes in java. 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment