public class MainClass {
public A wrap(int x) {
// Base constructor call:
return new A(x) { // Pass constructor argument.
public int value() {
return super.value() * 47;
}
}; // Semicolon required
}
public static void main(String[] args) {
MainClass p = new MainClass();
A w = p.wrap(10);
}
}
class A {
private int i;
public A(int x) {
i = x;
}
public int value() {
return i;
}
}
|