The syntax
new X(...) { ... }
instantiates an ad-hoc, anonymous class, extending / implementing the class / interface named X.
In your case, the abstract class has all it needs, there are no abstract methods. Therefore, the derived class doesn't need to implement any missing methods.
If you add an abstract method to your abstract class, the example will no longer work. To make it work again, you will have to implement the method in the { ... } section.
public abstract class MyAbstract
{
int num = 10;
abstract void f();
}
public static void main(String[] args) {
MyAbstract abstractObject = new MyAbstract() {
void f() {
...
}
};
System.out.println(abstractObject.num);
}
In addition, you can pass arguments to an extended base class's constructor by using the () part of the syntax:
public abstract class MyAbstract
{
MyAbstract(int argument) {
...
}
int num = 10;
abstract void f();
}
public static void main(String[] args) {
MyAbstract abstractObject = new MyAbstract(5) {
void f() {
...
}
};
System.out.println(abstractObject.num);
}