-2

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.

2
  • 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: docs.oracle.com/javase/tutorial/java/javaOO/nested.html Commented Dec 27, 2019 at 15:25
  • 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. Commented Dec 27, 2019 at 15:27

1 Answer 1

-1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.