您的位置:首页 > 编程语言 > Java开发

Java 匿名类示例

2016-07-17 12:04 232 查看
//匿名类
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;
}
}
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: