阅读下面的程序,分析代码是否能编译通过,如果能编译通过,请列出运行的结果。如果不能编译通过,请说明原因。代码一:Class RunHandler { public void run(){ System.out.println("run");}}Public class Test { public static void main(String ] args) { Thread t = new Thread(new RunHandler()); t.start();}}2代码二:Public class A extends Thread{ protected void run() { System.out.println("this is run()"); } public static void main(String] args) { A a = new A(); a .start(); }}3代码三:Public class Test{ private Object obj=new Object(); public synchronized void a(){ try { obj.wait(); System.out.println("waiting"); } catch (InterruptedException e) { System.out.println("Exception"); } } public static void main(String] args) { new Test().a(); }}4为了使下面的程序能够输出“Thread is running”,请在在空格处填上相应的代码。Public class B implements Runnable { public static void main(String] args) { Thread t = new Thread(new B()); ( )( )( )_____ //此处填空 } public void run() { System.out.println("Thread is running"); } public void go() { start(1); } public void start(int i) { }}
发布时间:2024-03-31 20:46:40