Normally, you can’t put any code inside an interface, but a nested class can be part of an interface. Any class you put inside an interface is automatically
public and
static. Since the class is
static, it doesn’t violate the rules for interfaces—the nested class is only placed inside the namespace of the interface. You can even implement the surrounding interface in the inner class.
TestBed: Use nested class to hold test code
public class TestBed {
public void f() {
System.out.println("f()");
}
public static class Tester {
public static void main(String[] args) {
TestBed t = new TestBed();
t.f();
}
}
}
No comments:
Post a Comment