public class A {
A(int p) {
System.out.println("带参构造子" + p);
}
A() {
System.out.println("无参构造子");
}
void method() {
System.out.println("fromA");
}
public static void main (String []args) {
new A().method();
A z = new A(){
void method() {
System.out.println("fram 匿名类0");
}
};// 分号不可缺
z.method() ;
A a = new A(1) {};
a.method() ;
A b = new A(2) {
void method() {
System.out.println("from 匿名类2");
};
};// 分号不可少
b.method();
}
}
08-02
4614
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-25
283
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)