网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

阅读下列程序:class ThreadTest extends Thread{ public static void main(String[]args){ Thread t=new Thread(this); t.start(); } public void run(){ System.out.print("A thread test."); }} 对该程序而言,正确结论是 ( )

A.该程序能够通过编译并打印输出“A thread test.”

B.该程序能够通过编译,但运行时将不调用ThreadTest类中的run()方法,因此不产生任何输出

C.该程序存在编译错误,因为在main()方法中不能使用this指针

D.上述选项都不正确


参考答案

更多 “ 阅读下列程序:class ThreadTest extends Thread{ public static void main(String[]args){ Thread t=new Thread(this); t.start(); } public void run(){ System.out.print("A thread test."); }} 对该程序而言,正确结论是 ( )A.该程序能够通过编译并打印输出“A thread test.”B.该程序能够通过编译,但运行时将不调用ThreadTest类中的run()方法,因此不产生任何输出C.该程序存在编译错误,因为在main()方法中不能使用this指针D.上述选项都不正确 ” 相关考题
考题 publicclassTestOne{publicstaticvoidmain(String[]args)throwsException{Thread.sleep(3000);System.out.println(”sleep”);}}Whatistheresult?() A.Compilationfails.B.Anexceptionisthrownatruntime.C.Thecodeexecutesnormallyandprints“sleep”.D.Thecodeexecutesnormally,butnothingisprinted.

考题 publicclassAextendsThread{A(){setDaemon(true);}publicvoidrun(){(newB()).start();try{Thread.sleep(60000);}catch(InterruptedExceptionx){}System.out.println(Adone”);}classBextendsThread{publicvoidrun(){try{Thread.sleep(60000);}catch(InterruptedExceptionx){}System.out.println(Bdone”);}}publicstaticvoidmain(String[]args){(newA()).start();}}Whatistheresult?()A.AdoneB.BdoneC.AdoneBdoneD.BdoneAdoneE.Thereisnoexceptionthattheapplicationwillprintanything.F.Theapplicationoutputs“Adone”and“Bdone”,innoguaranteedorder.

考题 下列程序通过设定线程优先级,抢占主线程的CPU,选择正确的语句填入横线处。 class T14 implements Runnable { private Boolean fStop - true; public void run() { while(fStop) { System.out.println(Thread.currentThread().getName() + "run"); try { Thread.sleep(l); } catch(Exception e) { e.printStackTrace(); } } } public void stopRun() { fStop = false; } } public class Testl4 { public static void main(String[] args) { T14 t14 = new T14(); Thread t1 = new Thread(ti4, "T14"); Thread t = Thread.currentThread()'; ______; Ti.start(); T14.stopRun(); System.out.println ( "stop "); } }A.setPriority(Thread. MIN_PRIORITY)B.t1 .setPriority(Thread. MIN_PRIORITY)C.t.setPfiofity(Thread. MIN_PRIORITY)D.t14.setPriority(Thread. MIN_PRIORITY)

考题 下列程序的执行结果是______。 class A5 extends Thread { boolean b; A5 (boolean bb) { b = bb; } public void run() { System.out.println(this.getName() + "运行"); } } public class Testl5 { public static void main(String[] args) { A5 a1 = new A5(true); A5 a2 = new A5(false); if(a1.b) A1.start(); if (a2 .b) A2.start(); } }A.Thread-0B.Thread-1C.Thread-0D.Thread-1 Thread-1 Thread-0

考题 Java.lang.Thread、java.lang.Number、java.lang.Double、java.lang.Math、java.lang.Void、java.lang.Class、java.lang.ClassLoader

考题 作为Java应用程序入口的main方法,其声明格式可以是( )。A、publicstaticvoidmain(String[]args)B、publicstaticintmain(String[]args)C、publicvoidmain(String[]args)D、publicintmain(String[]args)

考题 ●试题七阅读以下说明和Java代码,将解答写入答题纸的对应栏内。【说明】下面的程序的功能是利用实现Runnable接口的方法来创建线程,并利用它来执行响应的一些操作。最后使得m的执行结果:100,如图3。注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。class ClassName (1) Runnable{int n;(2) {try{ThreaD.sleep(2000);n=100;}catch( (3) e){}}public static void main(String[]args){try{ClassName a=new ClassName();(4)thread1. (5) ();thread1.join();int m=A.n;System.out.println("m="+m);}catch( (3) e){}}}

考题 阅读以下说明和Java程序,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。 【说明】 以下Java代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分接口、类及其关系如图5-1所示。 【Java代码】 interface?DrawCircle?{? //绘制圆形 public(1) ;}class?RedCircle?implements?DrawCircle?{? ?//绘制红色圆形???????public?void?drawCircle(int?radius,intx,?int?y)??{????????????System.out.println("Drawing?Circle[red,radius:"?+?radius?+",x:"?+?x?+?",y:"?+y+?"]");???????}}class?GreenCircle?implements?DrawCircle?{????//绘制绿色圆形??????public?void?drawCircle(int?radius,?int?x,int?y)?{???????????System.out.println("Drawing?Circle[green,radius:"?+radius+",x:?"?+x+?",y:?"?+y+?"]");??????}}abstract?class?Shape?{????//形状? protected? ? (2)???;? ? public?Shape(DrawCircle?drawCircle)?{? ?this.drawCircle=?drawCircle;? ? ? public?abstract?void?draw();}class?Circle?extends?Shape?{? //圆形? ?private?int?x,y,radius;? public?Circle(int?x,int?y,intradius,DrawCircle?drawCircle)?{? ?(3)???;? this.x?=?x;? ? ? this.y?=?y;? ?this.radius?=radius;? }? ? ?public?void?draw()?{? ? drawCircle.? ?(4)? ?;? ? ? }}public?class?DrawCircleMain?{? public?static?void?main(String[]?args)?{? Shape?redCircle=new?Circle(?100,100,10,? (5) );//绘制红色圆形? Shape?greenCircle=new?Circle(200,200,10,(6) );//绘制绿色圆形? ?redCircle.draw(); greenCircle.draw();? ?}}

考题 Java程序中,main方法的格式正确的是()A.public static void main(String[] args)B.public static main(String[] args)C.public void main(String[] args)D.static void main(String[] args)

考题 下列()选项是Java应用程序主类中正确的main()方法。A.public void main(String[] args)B.static void main(String[] args)C.public static void main(String args)D.public static void main(String[] args)