title: Why is a static local class not allowed in a method?
body: <p>I've been brushing off my java and I've some misunderstanding about local classes (that I ultimately never used), I well understand the concept of static but not in the case of <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/localclasses.html" rel="noreferrer">local classes</a>. </p>
  
  <p><strong>1. Why is a static method not allowed in a local classes ?</strong> </p>
  
  <p><strong>2. Why is a static local class not allowed in a method ?</strong> </p>
  
  <ol>
  <li>A static method not allowed in a local classes: </li>
  </ol>
  
  <p>Here I don't get it. To me the local class is tied to the static method main. I just don't understand why this cannot be done. The method main is accessed through the Sequence class and then since sayGoodbye is static it should be accessed through its class. But no. </p>
  
  <pre><code>public class Sequence {
  
      public static void main(String... args) {
  
          class EnglishGoodbye {
              public static void sayGoodbye() { // this cannot be done
                  System.out.println("Bye bye");
              }
          }
          EnglishGoodbye.sayGoodbye();
      }
  }
  </code></pre>
  
  <ol start="2">
  <li>A static local class not allowed in a method : </li>
  </ol>
  
  <p>This cannot be done: It's a bit ambiguous but I'd think a static here would have the same meaning as a non static since the static class is tied to a static method. I'm confused. </p>
  
  <pre><code>public class Sequence {
  
      public static void main(String... args) {
  
          static class EnglishGoodbye { //static local classes not allowed
              public static void sayGoodbye() {
                  System.out.println("Bye bye");
              }
          }
          EnglishGoodbye.sayGoodbye();
      }
  }
  </code></pre>
  
  <p><strong>Edit:</strong> 
   The first answer I got was a quote from oracle :</p>
  
  <blockquote>
    <p>Local classes are non-static because they have access to instance
    members of the enclosing block. Consequently, they cannot contain most
    kinds of static declarations.</p>
  </blockquote>
  
  <p>and my reply :  </p>
  
  <blockquote>
    <p>That doesn't really explain everything though. When you have an inner
    class you can't access non static fields but you can access static
    fields. Same should apply for a local class, and since there is no
    static variable then it's useless. But what about methods, like in my
    example.</p>
  </blockquote>
  
  <p>Okay I made a schema to better explain how I view things. It might be totally erroneous though and I'm a bit ashamed to show it. In this schema and in the scenario where a static local class <strong>would</strong> be accessible I'd have a local class in the top memory block. Whenever the static method2 would be called it would simply reference to it.</p>
  
  <p><a href="https://i.stack.imgur.com/PyXHz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/PyXHz.png" alt="enter image description here"></a></p>