-1

Referencing the following example:

class Plane {
    ...
    static class Gearbox {
        ...
    }
}

The following is possible:

Plane.Gearbox gearbox = new Plane.Gearbox();

I was wondering if someone could explain what effect the 'static' keyword has in this situation. Coming from C#, this is very strange to me as static classes cannot be instantiated.

I am well aware that there are other questions referring to the same topic, or information online, however I still don't fully understand the use of the 'static' keyword in this situation. Therefore I would greatly appreciate someones help to understand this concept in Java.

yeyi
  • 1
  • 1
    Java `static` nested classes have absolutely nothing to do with how `static class` works in C#. See this official tutorial for an explanation of how they work in Java: https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html – UnholySheep Dec 27 '19 at 15:25
  • https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html: **Note: A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.** - A static nested class is just like a typical top level class. – OH GOD SPIDERS Dec 27 '19 at 15:27

1 Answers1

-1

In Java, static means that an item is associated with the class itself and not with a specific instance of the class.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268