亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

線程類不能直接調用方法,必須使用構造方法嗎?下面兩個例子運行有什么不同

線程類不能直接調用方法,必須使用構造方法嗎?下面兩個例子運行有什么不同

超人TT 2016-07-29 16:40:49
1.public?class?DieThreadDemo?{ public?static?void?main(String[]?args)?{ Example?example=new?Example(); helloThread1?thread1=new?helloThread1(example); thread1.start(); helloThread2?thread2=new?helloThread2(example); thread2.start(); } } class?helloThread1?extends?Thread{ private?Example?example=null; public?helloThread1(Example?example){ this.example=example; } @Override public?void?run()?{ example.method1(); } } 2.public?class?hello?{ public?static?void?main(String[]?args)?{ helloThread1?thread1=new?helloThread1(); thread1.start(); helloThread2?thread2=new?helloThread2(); thread2.start(); } } class?helloThread1?extends?Thread{ Example?example=new?Example(); public?void?run(){ example.method1(); } }
查看完整描述

1 回答

?
風一般的男人

TA貢獻6條經驗 獲得超3個贊

java里面是new Thread().start(),就是都是先實例化類,在調用run()方法,然后再通過run()方法調用其他方法。

不同之處在于,第一種可以向子線程傳值,而第二種不能傳值,因為第二種線程的構造方法只有空的構造方法。

查看完整回答
反對 回復 2016-08-01
  • 1 回答
  • 0 關注
  • 1357 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號