问题:单选题public class Threads3 implements Runnable { public void run() { System.out.print(”running”); } public static void main(String[] args) { Thread t = new Thread(new Threads3()); t.run(); t.run(); t.start(); } } What is the result?()ACompilation fails.BAn exception is thrown at runtime.CThe code executes and prints “running”.DThe code executes and prints “runningrunning”.EThe code executes and prints “runningrunningrunning”.
查看答案
问题:单选题1. class A implements Runnable ( 2. int i; 3. public void run ( ) ( 4. try ( 5. thread.sleep(5000); 6. i= 10; 7. ) catch(InterruptedException e) {} 8. ) 9. ) 10. 11. public class Test { 12. public static void main (string args[]) ( 13. try ( 14. A a = new A ( ); 15. Thread t = new Thread (a); 16. t.start( ); 17. 18. int j= a.i; 19. 20. ) catch (Exception e) {} 21. ) 22. } Which statement al line 17 will ensure that j=10 at line 19?()Aa.wait();Bt.wait();Ct.join();Dt.yield();Et.notify();Fa.notify();Gt.interrupt();
问题:单选题Which gets the name of the parent directory file “file.txt”?()AString name= File.getParentName(“file.txt”);BString name= (new File(“file.txt”)).getParent();CString name = (new File(“file.txt”)).getParentName();DString name= (new File(“file.txt”)).getParentFile();EDirectory dir=(new File (“file.txt”)).getParentDir(); String name= dir.getName();
问题:单选题int i = 0; while (true) { if(i==4) { break; } ++i; } System.out.println(“i=”+i); What is the result?()Ai = 0Bi = 3Ci = 4Di = 5ECompilation fails.
问题:单选题1. public class ForBar { 2. public static void main(String []args) { 3. int i = 0, j = 5; 4. tp: for (;;) { 5. i ++; 6. for(;;) 7. if(i > --j) break tp; 8. } 9. system.out.printIn(“i = ” + i + “, j = “+ j); 10. } 11. } What is the result?()AThe program runs and prints “i=1, j=0”BThe program runs and prints “i=1, j=4”CThe program runs and prints “i=3, j=4”DThe program runs and prints “i=3, j=0”EAn error at line 4 causes compilation to fail.FAn error at line 7 causes compilation to fail.
问题:单选题public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( “Finally” ); } } } What is the result?()AFinallyBCompilation fails.CThe code runs with no output.DAn exception is thrown at runtime.
问题:单选题Which code fragments will succeed in printing the last argument given on the command line to the standard output, and exit gracefully with no output if no arguments are given?() CODE FRAGMENT a: public static void main(String args[]) { if (args.length != 0) System.out.println(args[args.length-1]); } CODE FRAGMENT b: public static void main(String args[]) { try { System.out.println(args[args.length]); } catch (ArrayIndexOutOfBoundsException e) {} } CODE FRAGMENT c: public static void main(String args[]) { int ix = args.length; String last = args[ix]; if (ix != 0) System.out.println(last); } CODE FRAGMENT d: public static void main(String args[]) { int ix = args.length-1; if (ix > 0) System.out.println(args[ix]); } CODE FRAGMENT e: public static void main(String args[]) { try { System.out.println(args[args.length-1]); }catch (NullPointerException e) {} }A Code fragment a.B Code fragment b.C Code fragment c.D Code fragment d.E Code fragment e.
问题:单选题public class X { public object m () { object o = new float (3.14F); object oa = new object [1]; oa[0]= o; o = null; oa[0] = null; return o; } } When is the float object created in line 3, eligible for garbage collection?()AJust after line 5.BJust after line 6.CJust after line 7.DJust after line 8(that is, as the method returns).
问题:单选题public class Test { public static void leftshift(int i, int j) { i<<=j; } public static void main(String args[]) { int i = 4, j = 2; leftshift(i, j); System.out.printIn(i); } } What is the result?()A2B4C8D16EThe code will not compile.
问题:多选题Which declarations of identifiers are legal?()A$personsBTwoUsersC*pointDthisE_endline
问题:多选题11. public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. } Which three are valid on line 12?()AfinalBstaticCnativeDpublicEprivateFabstractGprotected
问题:单选题public class Person { private name; public Person(String name) { this.name = name; } public int hashCode() { return 420; } } Which is true?()AThe time to find the value from HashMap with a Person key depends on the size of the map.BDeleting a Person key from a HashMap will delete all map entries for all keys of typePerson.CInserting a second Person object into a HashSet will cause the first Person object to beremoved as a duplicate.DThe time to determine whether a Person object is contained in a HashSet is constant and does NOT depend on the size of the map.
问题:单选题Given the following code fragment: 1) String str = null; 2) if ((str != null) && (str.length() > 10)) { 3) System.out.println("more than 10"); 4) } 5) else if ((str != null) & (str.length() < 5)) { 6) System.out.println("less than 5"); 7) } 8) else { System.out.println("end"); } Which line will cause error?()Aline 1Bline 2Cline 5Dline 8
问题:单选题public class X implements Runnable( private int x; private int y; public static void main(Stringargs) X that = new X(); (new Thread(that)).start(); (new Thread(that)).start(); ) public void run() ( for (;;) ( x++; y++; System.out.printIn(“x=” + x + “, y = ” + y); ) ) What is the result?()AErrors at lines 7 and 8 cause compilation to fail.BThe program prints pairs of values for x and y that might not always be the same on the same line (for example, “x=2, y=1”).CThe program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=1, y=1”).DThe program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears only for once (for example, “x=1, y=1” followed by “x=2, y=2”).
问题:多选题Which of these are keywords in Java?()AdefaultBNULLCStringDthrowsElong
问题:多选题Which statements concerning the relationships between the following classes are true?() class Foo { int num; Baz comp = new Baz(); } class Bar { boolean flag; } class Baz extends Foo { Bar thing = new Bar(); double limit; }AA Bar is a Baz.BA Foo has a Bar.CA Baz is a Foo.DA Foo is a Baz.EA Baz has a Bar.
问题:填空题3. string foo = “ABCDE”; 4. foo.substring(3); 5. foo.concat(“XYZ”); 6. Type the value of foo at line 6.()
问题:单选题You want a class to have access to members of another class in the same package. Which is the most restrictive access modifier that will accomplish that will accomplish this objective?()APublicBPrivateCProtectedDTransientENo access modifier is required.
问题:单选题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?()ABDBBCDCBDEDBCDEEABCDEFCompilation fails.
问题:单选题Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?() class A {} class B extends A {} class C extends A {} public class Q3ae4 { public static void main(String args[]) { A x = new A(); B y = new B(); C z = new C(); // insert statement here } }A x = y;B z = x;C y = (B) x;D z = (C) y;E y = (A) y;