版权声明:本文为博主原创文章,转载请注明原博客地址。 https://blog.csdn.net/u012210441/article/details/51931661
//匿名类
interface Contents{
int value();
}
public class Parcel4 {
public Contents cont(){
return new Contents(){
private int i = 11;
public int value(){
return i;
}
};//此处需要分号,表示匿名类的结束
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Parcel4 p = new Parcel4();
Contents c = p.cont();
System.out.println("" + c.value());
}
}
/*
class MyContents implements Contents{
private int i = 11;
public int value(){
return i;
}
}
*/