A a = new A(){};
生成一个匿名的子类实现,因为A中的构造器是
protected
不能直接new但是子类可以调用;
public class B extends A{
B (){
super();
}
}
Here’s what happens when that line is executed:
An anonymous subclass of SomeClass is created.
That anonymous subclass is given a default no-argument constructor, just like any other Java class that is declared without a no-argument constructor.
The default no-argument constructor is defined with visibility public
The default no-argument constructor is defined to call super() (which is what no-arg constructors always do first).
The new command calls the no-argument constructor of this anonymous subclass and assigns the result to a