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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© Tsinvat 中级黑马   /  2014-10-22 18:28  /  810 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

import java.util.*;
public class ThreadDemo
{
        public static void main(String[] args)
        {
                Demo d= new Demo();
                d.start();//只是调用了start方法怎么跑了run?
                System.out.println("主线程跑");
        }
       
}
class Demo extends Thread
{       
        public void run()
        {
                System.out.println("2号线程跑");
        }
}

评分

参与人数 1技术分 +1 收起 理由
敏敏好学 + 1

查看全部评分

3 个回复

倒序浏览
这涉及到源码了吧。。。 调用start方法,虚拟机就自动调用这个线程的run方法
回复 使用道具 举报
extends Thread
继承线程了
回复 使用道具 举报
start
public void start()
Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
这是在Java API里Thread类里找到的start()方法的描述。 这个线程开始执行的原因,是Java虚拟机调用了这个线程的run方法。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马