A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© ziyu0971 中级黑马   /  2015-2-4 14:53  /  1237 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

new Thread(new Runnable(){  //匿名
                        public void run(){
                                System.out.println("runnable run");       
                        }
                })
                {
                        public void run(){
                                System.out.println("subthread run");
                        }
                }.start();  //结果:subthread run

4 个回复

倒序浏览
不知道你这个完整类是什么样子的 是这个样子的吗
public class Test extends Thread {
        {
                new Thread(new Runnable(){  //匿名
            public void run(){
                System.out.println("runnable run");        
        }
   })
   {
        public void run(){
                System.out.println("subthread run");
        }
   }.start();
}
        public static void main(String[] args) {
                Test t=new Test();
        //        t.start();
        }
}
回复 使用道具 举报
可以理解成是一个覆盖。
回复 使用道具 举报
回复 使用道具 举报
再見螢火蟲 发表于 2015-2-4 17:49
不知道你这个完整类是什么样子的 是这个样子的吗
public class Test extends Thread {
        {

是的,前面是一个匿名内部类调用了start方法。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马