title: How to create an object of a class that lives within a method in Java?
body: <p>I have following class:</p>
  <pre><code>public class SomeClass {
      public static void main(String[] args) {
          //
      }
  
      private static void test() {
          MyClass myClass = new MyClass(); //Doesn't work
          myClass.print(); //Doesn't work
  
          class MyClass {
              void print() {
                  System.out.println(&quot;Some text&quot;);
              }
          }
      }
  }
  </code></pre>
  <p>How to create an object of type <code>MyClass</code>? Both lines produce compilation error.</p>