子类中重新定义父类属性
1 | package com.imooc.thread;<br><br> class MyThread1 extends Thread{<br> private String name;<br> public MyThread1(String name) {<br> this .name = name;<br> }<br><br> public void run() {<br> for ( int i = 0 ; i < 30 ; i++) {<br> System.out.println(Thread.currentThread().getName()+ "正在运行" +i);<br> }<br> }<br>}<br><br> public class ThreadTest5 {<br> public static void main(String[] args) {<br> MyThread1 thread1 = new MyThread1( "thread1" );<br> MyThread1 thread2 = new MyThread1( "thread2" );<br><br> thread1.setPriority(Thread.MAX_PRIORITY);<br> thread2.setPriority(Thread.MIN_PRIORITY);<br><br> thread1.start();<br> thread2.start();<br> }<br>}<br> |
对于上面这段代码里面的MyThread1类继承了Thread类,同时定义了一个name属性,我想问一下,有必要重新定义name属性吗?Thread类里面不是有name属性吗
13
收起
正在回答 回答被采纳积分+1
1回答
java工程师2020版
- 参与学习 人
- 提交作业 9402 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧