If I have something like this:
public class Outer {
private class Inner {
public void someMethod() {}
}
Inner in = new Inner();
in.someMethod(); //What??
}
Why doesn't last line code work?
Why doesn't last line code work?
Because it has to be wrapped within a block ( initializer , constructor , method ).
For example (wrapper within a constructor):
public class Outer {
private class Inner {
public void someMethod() {}
}
public Outer() {
Inner in = new Inner();
in.someMethod();
}
}
You just cant invoke any method directly from class body. It has to be a method or constructor or initilizer block
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.