问题:单选题class Parent { String one, two; public Parent(String a, String b){ one = a; two = b; } public void print(){ System.out.println(one); } } public class Child extends Parent { public Child(String a, String b){ super(a,b); } public void print(){ System.out.println(one + " to " + two); } public static void main(String arg[]){ Parent p = new Parent("south", "north"); Parent t = new Child("east", "west"); p.print(); t.print(); } } Which of the following is correct?()ACause error during compilation. Bsouth east Csouth to north east to west Dsouth to north east Esouth east to west
查看答案
问题:单选题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.
问题:单选题public class Threads4 { public static void main (String[] args) { new Threads4().go(); } public void go() { Runnable r = new Runnable() { public void run() { System.out.print(”foo”); } }; Thread t = new Thread(r); t.start(); t.start(); } } What is the result?()ACompilation fails.BAn exception is thrown at runtime.CThe code executes normally and prints „foo”.DThe code executes normally, but nothing is printed.
问题:单选题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?()AABCDBCompilation fails.CC is printed before exiting with an error message.DBC is printed before exiting with an error message.EBCD is printed before exiting with an error message.
问题:单选题interface Data { public void load(); } abstract class Info { public abstract void load(); } Which class correctly uses the Data interface and Info class?()Apublic class Employee extends Info implements Data { public void load() { /*do something*/ } }Bpublic class Employee implements Info extends Data { public void load() { /*do something*/ } }Cpublic class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }Dpublic class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }Epublic class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }Fpublic class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }
问题:单选题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.
问题:单选题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();
问题:单选题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”).
问题:多选题In which two cases does the compiler supply a default constructor for class A?()Aclass A{}Bclass A { public A(){} }Cclass A { public A(int x){} }Dclass Z {} class A extends Z { void A(){} }
问题:多选题Which of these are keywords in Java?()AdefaultBNULLCStringDthrowsElong
问题:单选题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 Test { public static void main (String args) { class Foo { public int i = 3; } Object o = (Object) new Foo(); Foo foo = (Foo)o; System.out.printIn(foo. i); } } What is the result?()ACompilation will fail.BCompilation will succeed and the program will print “3”CCompilation will succeed but the program will throw a ClassCastException at line 6.DCompilation will succeed but the program will throw a ClassCastException at line 7.
问题:单选题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;
问题:多选题Integer i = new Integer (42); Long 1 = new Long (42); Double d = new Double (42.0); Which two expressions evaluate to True?()A(i ==1)B(i == d)C(d == 1)D(i.equals (d))E(d.equals (i))F(i.equals (42)
问题:单选题Which code, inserted at line 16, will cause a java.lang.ClassCastException?()AAlpha a=x;BFoo f=(Delta)x;CFoo f=(Alpha)x;DBeta b=(Beta)(Alpha)x;
问题:多选题11. public interface Status { 12. /* insert code here */ int MY_VALUE = 10; 13. } Which three are valid on line 12?()AfinalBstaticCnativeDpublicEprivateFabstractGprotected
问题:单选题public class AssertStuff { public static void main(String [] args) { int x= 5; int y= 7; assert (x> y): “stuff”; System.out.println(”passed”); } } And these command line invocations:java AssertStuff java -ea AssertStuff What is the result?()Apassed stuffBstuff passedCpassed An AssertionError is thrown with the word “stuff” added to the stack trace.Dpassed An AssertionError is thrown without the word “stuff” added to the stack trace.Epassed An AssertionException is thrown with the word “stuff” added to the stack trace.Fpassed An AssertionException is thrown without the word “stuff” added to the stack trace.
问题:单选题public class test( public static void main(stringargs){ string foo = args [1]; string foo = args ; string foo = args ; } ) And command line invocation: Java Test red green blue What is the result? ()ABaz has the value of “”BBaz has the value of nullCBaz has the value of “red”DBaz has the value of “blue”EBax has the value of “green”FThe program throws an exception.
问题:单选题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.()