问题:多选题class A { } class Alpha { private A myA = new A(); void dolt( A a ) { a = null; } void tryIt() { dolt( myA ); } } Which two statements are correct?()AThere are no instanced of A that will become eligible for garbage collection.BExplicitly setting myA to null marks that instance to be eligible for garbage collection.CAny call on tryIt() causes the private instance of A to be marked for garbage collection.DPrivate instances of A become eligible for garbage collection when instances of Alpha become eligible for garbage collection.
Thursday, October 5, 2023
问题:多选题AnInterface is an interface. AnAdapter0 is a non-abstract, non-final class with a zero argument constructor. AnAdapter1 is a non-abstract, non-final class without a zero argument constructor, but with a constructor that takes one int argument. Which two construct an anonymous inner class? ()AAnAdapter1 aa=new AnAdapter1(){}BAnAdapter0 aa=new AnAdapter0(){}CAnAdapter0 aa=new AnAdapter0(5){}DAnAdapter1 aa=new AnAdapter1(5){}EAnInterface a1=new AnInterface(5){}
Monday, October 2, 2023
问题:填空题5. String foo = “base”; 6. foo.substring(0,3); 7. foo.concat(“ket”) 8. Type the value of foo at line 8.()
Thursday, September 22, 2022
问题:单选题10. interface A { void x(); } 11. class B implements A { public void x() { } public voidy() { } } 12. class C extends B { public void x() {} } And: 20. java.util.List list = new java.util.ArrayList(); 21. list.add(new B()); 22. list.add(new C()); 23. for (A a:list) { 24. a.x(); 25. a.y();; 26. } What is the result?()AThe code runs with no output.BAn exception is thrown at runtime.CCompilation fails because of an error in line 20.DCompilation fails because of an error in line 21.ECompilation fails because of an error in line 23.FCompilation fails because of an error in line 25.
Wednesday, September 21, 2022
问题:单选题public class Foo { public void main( String[] args ) { System.out.println( “Hello” + args[0] ); } } What is the result if this code is executed with the command line?()AHelloBHello FooCHello worldDCompilation fails.EThe code does not run.
Saturday, July 8, 2023
问题:单选题Which of the following range of short is correct?()A-27 -- 27-1B0 -- 216-1C-215 -- 215-1D-231 -- 231-1
Sunday, July 30, 2023
问题:多选题public class SyncTest{ public static void main(String args) { final StringBuffer s1= new StringBuffer(); final StringBuffer s2= new StringBuffer(); new Thread () { public void run() { synchronized(s1) { s2.append(“A”); synchronized(s2) { s2.append(“B”); System.out.print(s1); System.out.print(s2); } } } }.start(); new Thread() { public void run() { synchronized(s2) { s2.append(“C”); synchronized(s1) { s1.append(“D”); System.out.print(s2); System.out.print(s1); } } } }.start(); } } Which two statements are true? ()AThe program prints “ABBCAD”BThe program prints “CDDACB”CThe program prints “ADCBADBC”DThe output is a non-deterministic point because of a possible deadlock condition.EThe output is dependent on the threading model of the system the program is running on.
问题:单选题public class Ball { public enum Color { RED, GREEN, BLUE }; public void foo() { // insert code here { System.out.println(c); } } } Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?()Afor( Color c : Color.values())Bfor( Color c = RED; c <= BLUE; c++)Cfor( Color c; c.hasNext() ; c.next())Dfor( Color c = Color[0]; c <= Color[2]; c++)Efor( Color c = Color.RED; c <= Color.BLUE; c++)
Monday, September 19, 2022
问题:多选题Which two CANNOT directly cause a thread to stop executing?()ACalling the yield method.BCalling the wait method on an object.CCalling the notify method on an object.DCalling the notifyAll method on an object.ECalling the start method on another Thread object.
问题:多选题Which two valid declarations of a char?()AChar ch = “a”;BChar ch = ‘/’ ‘;CChar ch = ‘cafe’;DChar ch = “cafe”;EChar ch = ‘/ucafe’;FChar ch = ‘/u10100’;GChar ch = (char) true;
Sunday, March 31, 2024
问题:多选题public class TestString3 { public static void main(String[] args) { // insert code here System.out.println(s); } } Which two code fragments, inserted independently at line 3, generate the output 4247?()AString s = “123456789”; s = (s-”123”).replace(1,3,”24”) - “89”;BStringBuffer s = new StringBuffer(”123456789”); s.delete(0,3).replace( 1,3, “24”).delete(4,6);CStringBuffer s = new StringBuffer(”123456789”); s.substring(3,6).delete( 1 ,3).insert(1, “24”);DStringBuilder s = new StringBuilder(”123456789”); s.substring(3,6).delete( 1 ,2).insert( 1, “24”);EStringBuilder s = new StringBuilder(”123456789”); s.delete(0,3).delete( 1 ,3).delete(2,5).insert( 1, “24”);
问题:多选题Which statements about inheritance are true?()AIn Java programming language only allows single inheritance.BIn Java programming language allows a class to implement only one interface.CIn Java programming language a class cannot extend a class and implement a interface together.DIn Java programming language single inheritance makes code more reliable.
Tuesday, September 20, 2022
问题:单选题public class Threads5 { public static void main (String[] args) { new Thread(new Runnable() { public void run() { System.out.print(”bar”); } }).start(); } } What is the result?()ACompilation fails.BAn exception is thrown at runtime.CThe code executes normally and prints “bar”.DThe code executes normally, but nothing prints.
Wednesday, February 8, 2023
问题:单选题public class Test { private static int[] x; public static void main(String[] args) { System.out.println(x[0]); } } What is the result?()A0BnullCCompilation fails.DA NullPointerException is thrown at runtime.EAn ArrayIndexOutOfBoundsException is thrown at runtime.
问题:单选题public class ClassA { public int getValue() { int value=0; boolean setting = true; String title=”Hello”; (value || (setting && title == “Hello”)) { return 1; } (value == 1 & title.equals(”Hello”)) { return 2; } } } And: ClassA a = new ClassA(); a.getValue(); What is the result?()A1B2CCompilation fails.DThe code runs with no output.EAn exception is thrown at runtime.
Monday, January 30, 2023
问题:多选题Which two valid declarations of a char? ()AChar ch = “a”;BChar ch = ‘“‘ ‘;CChar ch = ‘cafe‘;DChar ch = “cafe”;EChar ch = ‘“ucafe‘;FChar ch = ‘“u10100‘;GChar ch = (char) true;
问题:单选题import java.util.*; class KeyMaster { public int i; public KeyMaster(int i) { this.i = i; } public boolean equals(Object o) { return i == ((KeyMaster)o).i; } public int hashCode() { return i; } } public class MapIt { public static void main(String[] args) { Set set = new HashSet(); KeyMaster k1 = new KeyMaster(1); KeyMaster k2 = new KeyMaster(2); set.add(k1); set.add(k1); set.add(k2); set.add(k2); System.out.print(set.size() + “:”); k2.i = 1; System.out.print(set.size() + “:”); set.remove(k1); System.out.print(set.size() + “:”); set.remove(k2); System.out.print(set.size()); } } What is the result?()A4:4:2:2B4:4:3:2C2:2:1:0D2:2:0:0E2:1:0:0F2:2:1:1G4:3:2:1
Sunday, February 26, 2023
问题:单选题10. class Line { 11. public class Point { public int x,y; } 12. public Point getPoint() { return new Point(); } 13. } 14. class Triangle { 15. public Triangle() { 16. // insert code here 17. } 18. } Which code, inserted at line 16, correctly retrieves a local instance of a Point object?()APoint p = Line.getPoint();BLine.Point p = Line.getPoint();CPoint p = (new Line()).getPoint();DLine.Point p = (new Line()).getPoint();
Thursday, September 15, 2022
问题:单选题Which method is an appropriate way to determine the cosine of 42 degrees?()ADouble d = Math.cos(42);BDouble d = Math.cosine(42);CDouble d = Math.cos(Math.toRadians(42));DDouble d = Math.cos(Math.toDegrees(42));EDouble d = Math.cosine(Math.toRadians(42));
问题:单选题How can you create a listener class that receives events when the mouse is moved?()ABy extending MouseListener.BBy implementing MouseListener.CBy extending MouseMotionListener.DBy implementing MouseMotionListener.EEither by extending MouseMotionListener or extending MouseListener.FEither by implementing MouseMotion Listener or implementing MouseListener.
Wednesday, May 10, 2023