On changing non-static inner class to static why there are compile time error on running code says-
Illegal enclosing instance specification
public class TestingInnerStatic{
public static void main(String args[]) {
InnerSame innerSame = new TestingInnerStatic().new InnerSame();//compile fail
Outer.InnerDiff innerDiff = new Outer().new InnerDiff();//compile fail
}
public void main() {
InnerSame innerSame = new InnerSame();
Outer.InnerDiff innerDiff = new Outer().new InnerDiff();//compile fail
}
static class InnerSame{}
}
class Outer{
static class InnerDiff{}
}
take a example of other member,this is only a convention and a good practice to call a static member on reference of class but if U call them on object they works not show compile fail.So why there is a compile fail?
new Boxing1().new InnerSame();shuld benew TestingInnerStatic().new InnerSame();