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

题目内容 (请给出正确答案)
单选题
public class TwoThreads {  private static Object resource = new Object();  private static void delay(long n) {  try { Thread.sleep(n); }  catch (Exception e) { System.out.print(”Error “); }  }  public static void main(String[] args) {  System.out.print(”StartMain “);  new Thread1().start();  delay(1000);  Thread t2 = new Thread2();  t2.start();  delay(1000);  t2.interrupt  delay(1000);  System.out.print(”EndMain “);  }  static class Thread 1 extends Thread {  public void run() {  synchronized (resource) {  System.out.print(”Startl “);  delay(6000);  System.out.print(”End1 “);  }  }  }  static class Thread2 extends Thread {  public void run() {  synchronized (resource) {  System.out.print(”Start2 “);  delay(2000);  System.out.print(”End2 “);  }  }  }  }  Assume that sleep(n) executes in exactly m milliseconds, and all other code executes in an insignificant amount of time. What is the output if the main() method is run?()
A

 Compilation fails.

B

 Deadlock occurs.

C

 StartMain Start1 Error EndMain End1

D

 StartMain Start1 EndMain End1 Start2 End2

E

 StartMain Start1 Error Start2 EndMain End2 End1

F

StartMain Start1 EndMain End1 Start2 Error End2


参考答案

参考解析
解析: 暂无解析
更多 “单选题public class TwoThreads {  private static Object resource = new Object();  private static void delay(long n) {  try { Thread.sleep(n); }  catch (Exception e) { System.out.print(”Error “); }  }  public static void main(String[] args) {  System.out.print(”StartMain “);  new Thread1().start();  delay(1000);  Thread t2 = new Thread2();  t2.start();  delay(1000);  t2.interrupt  delay(1000);  System.out.print(”EndMain “);  }  static class Thread 1 extends Thread {  public void run() {  synchronized (resource) {  System.out.print(”Startl “);  delay(6000);  System.out.print(”End1 “);  }  }  }  static class Thread2 extends Thread {  public void run() {  synchronized (resource) {  System.out.print(”Start2 “);  delay(2000);  System.out.print(”End2 “);  }  }  }  }  Assume that sleep(n) executes in exactly m milliseconds, and all other code executes in an insignificant amount of time. What is the output if the main() method is run?()A  Compilation fails.B  Deadlock occurs.C  StartMain Start1 Error EndMain End1D  StartMain Start1 EndMain End1 Start2 End2E  StartMain Start1 Error Start2 EndMain End2 End1F StartMain Start1 EndMain End1 Start2 Error End2” 相关考题
考题 下列程序的运行结果是public class test{private String[] data={“10”,“10.5”};public void fun(){double s=0;for(int i=0;i3;i++){try{s=s+Integer .parseInt(data[i]);}catch(Exception e){System.out.print(“errorl:”+data[i]);}}}public static void main(String[]args){try{testd=new test();d .fun();}catch(Exception e){System.out.printIn(“error2”);}}}A.errorl:10.5B.error2C.errorl:10.5 error2D.以上都不对

考题 static void test() throws RuntimeException {  try {  System.out.print(”test “);  throw new RuntimeException();  }  catch (Exception ex) { System.out.print(”exception “); }  }  public static void main(String[] args) {  try { test(); }  catch (RuntimeException ex) { System.out.print(”runtime “); }  System.out.print(”end “);  }  What is the result?() A、 test endB、 Compilation fails.C、 test runtime endD、 test exception endE、 A Throwable is thrown by main at runtime.

考题 public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (Exception ex) {  System.out.print(“C”);  }  finally {  System.out.print(“B”);  }  System.out.print(“D”);  }  public static void badMethod() {  throw new Error();  }  }  What is the result?()  A、 ABCDB、 Compilation fails.C、 C is printed before exiting with an error message.D、 BC is printed before exiting with an error message.E、 BCD is printed before exiting with an error message.

考题 static void test() {  try {  String x=null;  System.out.print(x.toString() +“ “);  }  finally { System.out.print(“finally “); }  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  }  What is the result?() A、 nullB、 finallyC、 null finallyD、 Compilation fails.E、 finally exception

考题 public class Test {  public static void aMethod() throws Exception {  try {  throw new Exception(); } finally {  System.out.println(“finally”);  }  }  public static void main(String args[]) {  try {  aMethod();  } catch (Exception e) {  System.out.println(“exception”);  }  System.out.println(“finished”);  }  }  What is the result?()  A、 finallyB、 exception finishedC、 finally exception finishedD、 Compilation fails.

考题 class ThreadExcept implements Runnable {   public void run() { throw new RuntimeException("exception "); }   public static void main(String [] args) {   new Thread(new ThreadExcept()).start();   try {   int x = Integer.parseInt(args[0]);   Thread.sleep(x);   System.out.print("main ");    } catch (Exception e) { }      }  }   和命令行:  java ThreadExcept 1000    哪一个是结果?()  A、 mainB、 编译失败C、 代码运行,但没有输出D、 main java.lang.RuntimeException:exception

考题 public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”); }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }   public static void badMethod() {} }  What is the result?()  A、 ACB、 BDC、 ACDD、 ABCDE、 Compilation fails.

考题 public class TwoThreads {  private static Object resource = new Object();  private static void delay(long n) {  try { Thread.sleep(n); }  catch (Exception e) { System.out.print(”Error “); }  }  public static void main(String[] args) {  System.out.print(”StartMain “);  new Thread1().start();  delay(1000);  Thread t2 = new Thread2();  t2.start();  delay(1000);  t2.interrupt  delay(1000);  System.out.print(”EndMain “);  }  static class Thread 1 extends Thread {  public void run() {  synchronized (resource) {  System.out.print(”Startl “);  delay(6000);  System.out.print(”End1 “);  }  }  }  static class Thread2 extends Thread {  public void run() {  synchronized (resource) {  System.out.print(”Start2 “);  delay(2000);  System.out.print(”End2 “);  }  }  }  }  Assume that sleep(n) executes in exactly m milliseconds, and all other code executes in an insignificant amount of time. What is the output if the main() method is run?() A、 Compilation fails.B、 Deadlock occurs.C、 StartMain Start1 Error EndMain End1D、 StartMain Start1 EndMain End1 Start2 End2E、 StartMain Start1 Error Start2 EndMain End2 End1F、StartMain Start1 EndMain End1 Start2 Error End2

考题 现有:  class Flow {  public static void main(String [] args)   try {  System. out .print ("before") ;   doRiskyThing ( )  ;   System.out.print ("after ") ;   } catch (Exception fe) {  System.out.print ("catch") ;   }  System. out .println ( " done") ;  }  public static void doRiskyThing() throws Exception{   // this code returns unless it throws an Exception           }}  可能会产生哪两项结果 ?()  A、 before catchB、 before after doneC、 before catch doneD、 before after catch

考题 public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (RuntimeException ex) {  System.out.print(“B”);  }  catch (Exception ex1) {  System.out.print(“C”);  }   finally {  System.out.print(“D”);  }  System.out.print(“E”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result?()  A、 BDB、 BCDC、 BDED、 BCDEE、 ABCDEF、 Compilation fails.

考题 public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result? () A、 ABB、 BCC、 ABCD、 BCDE、 Compilation fails.

考题 class Flow {  public static void main(String [] args) {  try {  System.out.print("before ");  doRiskyThing();  System.out.print("after ");  } catch (Exception fe) {  System.out.print("catch ");  }  System.out.println("done ");  }   public static void doRiskyThing() throws Exception {  // this code returns unless it throws an Exception  } }  可能会产生下面哪两项结果?() A、beforeB、before catchC、before after doneD、before catch done

考题 static void test() throws Error {  if (true) throw new AssertionError();  System.out.print(”test “);  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  System.out.print(”elld “);  }  What is the result?() A、 endB、 Compilation fails.C、 exception endD、 exception test endE、 A Throwable is thrown by main.F、 An Exception is thrown by main.

考题 现有:  class Birds {  public static void main (String  []  args)  {   try {  throw new Exception () ;    } catch (Exception e) {   try {   throw new Exception () ;  }  catch  (Exception e2)  {  System.out.print ("inner           "); }   System. out.print ( "middle" ) ;    }  System.out.print ("outer") ;    }    }  结果是()A、 inner outerB、 middle outerC、 inner middle outerD、.编译失败

考题 class Birds {  public static void main(String [] args) {  try {  throw new Exception();  } catch (Exception e) { try {  throw new Exception();  } catch (Exception e2) { System.out.print("inner "); }  System.out.print("middle "); }  System.out.print("outer ");  }  }  结果为:()  A、innerB、inner outerC、middle outerD、inner middle outer

考题 class Order implements Runnable {    public void run ()  {  try { Thread.sleep (2000) ;  } catch (Exception e)    System.out.print("in") ;  public static void main (String [] args)  {    Thread t = new Thread (new Order ()) ;    t.start () ;  System.out.print ("pre ") ;  try { t.join () ;  } catch (Exception e)  { }    System.out.print ("post") ;   可产生哪两项结果?()  A、 pre in postB、 pre inC、 in post preD、 in pre postE、 pre post in

考题 单选题public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (RuntimeException ex) {  System.out.print(“B”);  }  catch (Exception ex1) {  System.out.print(“C”);  }   finally {  System.out.print(“D”);  }  System.out.print(“E”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result?()A  BDB  BCDC  BDED  BCDEE  ABCDEF  Compilation fails.

考题 单选题static void test() {  try {  String x=null;  System.out.print(x.toString() +“ “);  }  finally { System.out.print(“finally “); }  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  }  What is the result?()A  nullB  finallyC  null finallyD  Compilation fails.E  finally exception

考题 单选题现有:  class Birds {  public static void main (String  []  args)  {   try {  throw new Exception () ;    } catch (Exception e) {   try {   throw new Exception () ;  }  catch  (Exception e2)  {  System.out.print ("inner           "); }   System. out.print ( "middle" ) ;    }  System.out.print ("outer") ;    }    }  结果是()A  inner outerB  middle outerC  inner middle outerD .编译失败

考题 单选题public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (Exception ex) {  System.out.print(“C”);  }  finally {  System.out.print(“B”);  }  System.out.print(“D”);  }  public static void badMethod() {  throw new Error();  }  }  What is the result?()A  ABCDB  Compilation fails.C  C is printed before exiting with an error message.D  BC is printed before exiting with an error message.E  BCD is printed before exiting with an error message.

考题 单选题static void test() throws RuntimeException {  try {  System.out.print(”test “);  throw new RuntimeException();  }  catch (Exception ex) { System.out.print(”exception “); }  }  public static void main(String[] args) {  try { test(); }  catch (RuntimeException ex) { System.out.print(”runtime “); }  System.out.print(”end “);  }  What is the result?()A  test endB  Compilation fails.C  test runtime endD  test exception endE  A Throwable is thrown by main at runtime.

考题 单选题下列程序的运行结果是(  )。public class test{private String [] data = {"10","10.5"};public void fun(){ double s = 0; for(int i = 0; i try{ s = s + Integer.parseInt(data[i]); } catch(Exception e){ System.out.print("error1:" + data[i]); } }}public static void main(String[] args){ try{ test d = new test(); d.fun(); } catch(Exception e){ System.out.println("error2"); }} }A error1:10.5B error2C error1:10.5error2D 以上都不对

考题 单选题public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result? ()A  ABB  BCC  ABCD  BCDE  Compilation fails.

考题 单选题static void test() throws Error {  if (true) throw new AssertionError();  System.out.print(”test “);  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  System.out.print(”elld “);  }  What is the result?()A  endB  Compilation fails.C  exception endD  exception test endE  A Throwable is thrown by main.F  An Exception is thrown by main.

考题 多选题class Order implements Runnable {  public void run() {  try { Thread.sleep(2000); } catch (Exception e) { }  System.out.print("in ");  }  public static void main(String [] args) {  Thread t = new Thread(new Order());  t.start();  System.out.print("pre ");  try { t.join(); } catch (Exception e) { }  System.out.print("post ");  } }  可产生哪两项结果?()Ain preBpre inCin pre postDpre in post

考题 单选题class Birds {  public static void main(String [] args) {  try {  throw new Exception();  } catch (Exception e) { try {  throw new Exception();  } catch (Exception e2) { System.out.print("inner "); }  System.out.print("middle "); }  System.out.print("outer ");  }  }  结果为:()A innerB inner outerC middle outerD inner middle outer

考题 单选题public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”); }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }   public static void badMethod() {} }  What is the result?()A  ACB  BDC  ACDD  ABCDE  Compilation fails.