<pre><code>public class Test {
    public static void main(String[] args) {

    }
}

class Outer {
    void aMethod() {
        class MethodLocalInner {
            void bMethod() {
                System.out.println("Inside method-local bMethod");
            }
        }
    }
}
</code></pre>

<p>Can someone tell me how to print the message from <code>bMethod</code>?</p>

[{'answer_id': 80615, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': True, 'text': '<p>You can only instantiate <code>MethodLocalInner</code> within <code>aMethod</code>. So do </p>\n\n<pre><code>void aMethod() {\n\n    class MethodLocalInner {\n\n            void bMethod() {\n\n                    System.out.println("Inside method-local bMethod");\n            }\n    }\n\n    MethodLocalInner foo = new MethodLocalInner(); // Default Constructor\n    foo.bMethod();\n\n}\n</code></pre>\n'}, {'answer_id': 80616, 'author': 'Benno Richters', 'author_id': 3565, 'author_profile': 'https://Stackoverflow.com/users/3565', 'pm_score': 1, 'selected': False, 'text': '<p>Within the method <em>aMethod</em> after the declaration of the class <em>MethodLocalInner</em> you could for instance do the following call:</p>\n\n<pre><code>new MethodLocalInner().bMethod();\n</code></pre>\n'}, {'answer_id': 80625, 'author': 'Lior', 'author_id': 13321, 'author_profile': 'https://Stackoverflow.com/users/13321', 'pm_score': 1, 'selected': False, 'text': "<p>Why don't you just create an instance of <code>MethodLocalInner</code>, in <code>aMethod</code>, and call <code>bMethod</code> on the new instance?</p>\n"}, {'answer_id': 19292897, 'author': 'Fco Javier Perez', 'author_id': 2866485, 'author_profile': 'https://Stackoverflow.com/users/2866485', 'pm_score': 0, 'selected': False, 'text': '<p>You need to call new Outer().aMethod() inside your main method. You also need to add a reference to MethodLocalInner().bMethod() inside your aMethod(), like this:</p>\n\n<pre><code>public class Test {\n    public static void main(String[] args) {\n        new Outer().aMethod();\n    }\n}\n\n\nvoid aMethod() {\n    class MethodLocalInner {\n        void bMethod() {\n            System.out.println("Inside method-local bMethod");\n        }\n    }\n    new MethodLocalInner().bMethod();\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/80592', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11193/']