Inner classes in Java - Non static variable error
问题 Im still new to java and i tried to create a inner class and call the method inside main. But theres a compilation error saying "Non static variable - This cannot be referenced from a static context" Please help class Class1{ public static void main(String args []){ Class2 myObject = new Class2(); myObject.newMethod(); } public class Class2{ public void newMethod(){ System.out.println("Second class"); } } } 回答1: An inner class needs a reference to an instance of the outer class in order to be