Home > Java > javaTutorial > What are the characteristics of nested classes in java

What are the characteristics of nested classes in java

PHPz
Release: 2023-05-03 11:19:06
forward
1003 people have browsed it

1. Concept

A nested class is a member of its outer class. A non-static nested class (inner class) can access other members of the outer class, even if the member is private of. A static nested class can only access static members of the outer class.

2. Features

(1) Nested category is the only internal category among the four categories, excluding external category objects.

(2) You can define static members.

(3) Can access any external static data members and methods. Constructors are considered static methods and therefore accessible.

3. Example

import java.io.PrintStream;  
    static class OuterClass$Inner  
    {  
    OuterClass$StaticNestedClass(){}  
        void getData(){  
            System.out.println((new StringBuilder()).append("data is ")
            .append(OuterClass.data).toString());  
    }    
}
Copy after login

What are the advantages of Java

1. Simple. As long as you understand the basic concepts, you can write programs suitable for various applications. Applications in this situation;

2. Object-oriented;

3. Distribution, Java is a network-oriented language;

4. Robustness, java provides automatic Garbage collection is used for memory management to prevent programmers from making errors when managing memory;

5. Security, Java used in network and distributed environments must prevent virus intrusion;

6. Architecture neutrality, as long as the Java runtime system is installed, it can run on any processor;

7. Portability, Java can be easily transplanted to different machines on the network;

8. Interpretation and execution. The Java interpreter directly interprets and executes the Java bytecode.

The above is the detailed content of What are the characteristics of nested classes in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template