java的super(),是干嘛的,什么作用啊??如下的程序
publicclassTest{publicstaticvoidmain(String[]args){NewThreadthread1=newNewThread();Ne...
public class Test
{
public static void main(String[] args)
{
NewThread thread1 = new NewThread();
NewThread thread2 = new NewThread();
thread1.start(); // start thread1
thread2.start(); // start thread2
}
}
/**
* create new thread by inheriting Thread
*/
class NewThread extends Thread {
private static int threadID = 0; // shared by all
/**
* constructor
*/
public NewThread() {
super("ID:" + (++threadID)); /////super(),是干嘛的,什么作用啊??
}
/**
* convert object to string
*/
public String toString() {
return super.getName();
}
/**
* what does the thread do?
*/
public void run() {
System.out.println(this);
}
}
//////////////
ID:1
ID:2
还有这个,return super.getName(); 什么作用啊? 展开
{
public static void main(String[] args)
{
NewThread thread1 = new NewThread();
NewThread thread2 = new NewThread();
thread1.start(); // start thread1
thread2.start(); // start thread2
}
}
/**
* create new thread by inheriting Thread
*/
class NewThread extends Thread {
private static int threadID = 0; // shared by all
/**
* constructor
*/
public NewThread() {
super("ID:" + (++threadID)); /////super(),是干嘛的,什么作用啊??
}
/**
* convert object to string
*/
public String toString() {
return super.getName();
}
/**
* what does the thread do?
*/
public void run() {
System.out.println(this);
}
}
//////////////
ID:1
ID:2
还有这个,return super.getName(); 什么作用啊? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询