What is the difference between an internal class and a static internal class in Java?

Asked 1 years ago, Updated 1 years ago, 76 views

What is the main difference between an internal class and a static internal class? Is it just a difference in design design?

java inner-classes nested-class

2022-09-22 22:37

1 Answers

Overlapping classes are divided into two categories. One is static. One is static. Static superposition laths are common It's called the static internal class, and the static is called the internal class.

    OuterClass.StaticNestedClass

Usually, static internal classes can be accessed by class names. So even if there are no objects in the outside class,

    OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass();

You can create objects.

In contrast, the inner class needs objects from the outer class surrounding the inner class as shown below to create objects.

    OuterClass outerObject = new OuterClass();
    OuterClass.InnerClass innerObject = outerObject.new InnerClass();


2022-09-22 22:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.