问题:单选题10. public class ClassA { 11. public void methodA() { 12. ClassB classB = new ClassB(); 13. classB.getValue(); 14. } 15. } And: 20. class ClassB { 21. public ClassC classC; 22. 23. public String getValue() { 24. return classC.getValue(); 25. } 26. } And: 30. class ClassC { 31. public String value; 32. 33. public String getValue() { 34. value = “ClassB”; 35. return value; 36. } 37. } Given: ClassA a = new ClassA(); a.methodA(); What is the result?()ACompilation fails.BClassC is displayed.CThe code runs with no output.DAn exception is thrown at runtime.
Wednesday, September 21, 2022
问题:单选题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;
Tuesday, September 5, 2023
问题:单选题Which is the return type of the method main()?AintBvoidCbooleanDstatic
Wednesday, January 4, 2023
问题:单选题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.
Thursday, September 22, 2022
问题:单选题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();
Thursday, January 18, 2024
问题:多选题Which of these are keywords in Java?()AdefaultBNULLCStringDthrowsElong
问题:单选题A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants to execute the main method of Poker on a UNIX system using the command: java games.cards.Poker What allows the user to do this?()A put Poker.jar in directory /stuff/java,and set the CLASSPATH to include /stuff/javaB put Poker.jar in directory /stuff/java,and set the CLASSPATH to include /stuff/java/*.jarC Put Poker.jar in directory /stuff/java,and set the CLASSPATH to include /stuff/java/Poker.jarD put Poker.jar in directory /stuff/java/games/cards,and set the CLASSPATH to include /stuff/javaE put Poker.jar in directory /stuff/java/games/cards,and set the CLASSPATH to include /stuff/java/*.jarF put Poker.jar in directory /stuff/java/games/cards,and set the CLASSPATH to include /stuff/java/Poker.jar
Sunday, September 18, 2022
问题:单选题public class Yippee2 { static public void main(String [] yahoo) { for(int x= 1; xSystem.out.print(yahoo[x] + “ “); } } } and the command line invocation: java Yippee2 a b c What is the result?()A a bB b cC a b cDCompilation fails.EAn exception is thrown at runtime.
Saturday, September 17, 2022
问题:单选题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.
问题:单选题public class SwitchTest { public static void main(String[] args) { System.out.println(“value = “ + switchIt(4)); } public static int switchIt(int x) { int j = 1; switch (x) { case 1: j++; case 2: j++; case 3: j++; case 4: j++; case 5: j++; default: j++; } return j + x; } } What is the result?()Avalue = 3Bvalue = 4Cvalue = 5Dvalue = 6Evalue = 7Fvalue = 8
Wednesday, September 14, 2022
问题:单选题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).
问题:填空题3. string foo = “ABCDE”; 4. foo.substring(3); 5. foo.concat(“XYZ”); 6. Type the value of foo at line 6.()
问题:多选题package com.company.application; public class MainClass { public static void main(String[] args) { } } And MainClass exists in the /apps/com/company/application directory. Assume the CLASSPATH environment variable is set to “.“ (current directory). Which two java commands entered at the command line will run MainClass?()Ajava MainClass if run from the /apps directoryBjava com.company.application.MainClass if run from the /apps directoryCjava -classpath /apps com.company.application.MainClass if run from any directoryDjava -classpath . MainClass if run from the /apps/com/company/application directoryEjava -classpath /apps/com/company/application:. MainClass if run from the /apps directoryFjava com.company.application.MainClass if run from the /apps/com/company/application directory
问题:单选题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.
Wednesday, January 10, 2024
问题:单选题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”).
问题:多选题Given the following code, which statements concerning the objects referenced through the member variables i, j and k are true, given that any thread may call the methods a, b and c at any time? () class Counter { int v = 0; synchronized void inc() { v++; } synchronized void dec() { v--; } } public class Q7ed5 { Counter i; Counter j; Counter k; public synchronized void a() { i.inc(); System.out.println("a"); i.dec(); } public synchronized void b() { i.inc(); j.inc(); k.inc(); System.out.println("b"); i.dec(); j.dec(); k.dec(); } public void c() { k.inc(); System.out.println("c"); k.dec(); } }Ai.v is guaranteed always to be 0 or 1.Bj.v is guaranteed always to be 0 or 1.Ck.v is guaranteed always to be 0 or 1Dj.v will always be greater than or equal to k.v at any give time.Ek.v will always be greater than or equal to j.v at any give time.
问题:单选题1) class Person { 2) public void printValue(int i, int j) {/*…*/ } 3) public void printValue(int i){/*...*/ } 4) } 5) public class Teacher extends Person { 6) public void printValue() {/*...*/ } 7) public void printValue(int i) {/*...*/} 8) public static void main(String args[]){ 9) Person t = new Teacher(); 10) t.printValue(10); 11) } 12) } Which method will the statement on line 10 call? ()Aon line 2Bon line 3Con line 6Don line 7
Thursday, May 25, 2023
问题:多选题A JavaBeans component has the following field: 11. private boolean enabled; Which two pairs of method declarations follow the JavaBeans standard for accessing this field?()Apublic void setEnabled( boolean enabled) public boolean getEnabled()Bpublic void setEnabled( boolean enabled) public void isEnabled()Cpublic void setEnabled( boolean enabled) public boolean isEnabled()Dpublic boolean setEnabled( boolean enabled) public boolean getEnabled()
问题:单选题11. rbo = new ReallyBigObject(); 12. // more code here 13. rbo = null; 14. /* insert code here */ Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object rbo?()ASystem.gc();BRuntime.gc();CSystem.freeMemory();DRuntime.getRuntime().growHeap();ERuntime.getRuntime().freeMemory();
问题:多选题11. public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. } Which three are valid on line 12?()AfinalBstaticCnativeDpublicEprivateFabstractGprotected
Thursday, October 5, 2023