32 lines
724 B
Java
32 lines
724 B
Java
//: innerclasses/AnonymousConstructor.java
|
|
// ©2015 MindView LLC: see Copyright.txt
|
|
// Creating a constructor for an anonymous inner class.
|
|
import static net.mindview.util.Print.*;
|
|
|
|
abstract class Base {
|
|
public Base(int i) {
|
|
print("Base constructor, i = " + i);
|
|
}
|
|
public abstract void f();
|
|
}
|
|
|
|
public class AnonymousConstructor {
|
|
public static Base getBase(int i) {
|
|
return new Base(i) {
|
|
{ print("Inside instance initializer"); }
|
|
@Override
|
|
public void f() {
|
|
print("In anonymous f()");
|
|
}
|
|
};
|
|
}
|
|
public static void main(String[] args) {
|
|
Base base = getBase(47);
|
|
base.f();
|
|
}
|
|
} /* Output:
|
|
Base constructor, i = 47
|
|
Inside instance initializer
|
|
In anonymous f()
|
|
*///:~
|