我用Java實現的接口和封裝在想,爲什麼這個代碼:接口和
package threaddemo;
// Create a new thread...
class NewThread implements Runnable {
Thread t;
NewThread(){
// Create a second, new thread...
t = new Thread(this, "Demo Thread");
System.out.println("Child thread: " + t);
t.start();
}
// This is the entry point for the second thread...
public void run(){
try {
for (int i=0; i<5; i++){
System.out.println("Child thread: " + i);
// Let the thread sleep for a while...
Thread.sleep(500);
}
} catch (InterruptedException e) {
System.out.println("Child interrupted...");
}
System.out.println("Exiting child thread...");
} }
public class ThreadDemo {
public static void main(String[] args) {
// Create a new thread...
new NewThread();
try {
for (int i=0; i<5; i++){
System.out.println("Main thread: " + i);
Thread.sleep(1000);
}
} catch (InterruptedException e){
System.out.println("Main thread itnerrupted...");
}
System.out.println("Main thread exiting...");
} }
生成以下警告它的左邊:
Package Field
當你實現接口,你是否可以訪問包含該接口的包中的類?我的包裏還沒有其他文件,我也沒有做任何類型的導入,所以我實際上有點困惑,因爲爲什麼這是可以開始...
你可以請發佈完整的警告?你的最後一段現在很難理解。 –
除此之外,它並沒有真正說出任何東西。如果有幫助,我在下面發佈了更多信息。 :-) –
如果有幫助,我添加了其餘的代碼。 –