当前位置: 代码迷 >> J2SE >> 什么是匿名内部类解决方案
  详细解决方案

什么是匿名内部类解决方案

热度:90   发布时间:2016-04-24 02:16:00.0
什么是匿名内部类
大家给我写个简单的例子,以及有什么注意事项

------解决方案--------------------
[code=Java][/code]public class Parcel6 {
public Contents cont() {
return new Contents() {
private int i = 11;
public int value() { return i; }
}; // Semicolon required in this case
}
public static void main(String[] args) {
Parcel6 p = new Parcel6();
Contents c = p.cont();
}
} ///:~
------解决方案--------------------
只会给一个例子,注意事项不是很懂~
Java code
public class Test {    public static void main(String[] args) {        Thread t = new Thread() {            private int i = 0;            public void run() {                while(true) {                    System.out.println("i = " + i++);                }            }        };        t.start();    }}
  相关解决方案