本页仅为文字内容,不可回答。

中国联通-Java开发与实践培训结业考试2018.3.21

欢迎参加本次结业考试,祝您考试顺利!
请填写您的姓名:
    ____________
请填写您的公司邮箱:
    ____________
以下题型为不定项选择题
35. String #name = Jane Doe;36. int $age=24;37. Double _height = 123.5;38. double ~temp = 37.5;Which two are true? (Choose two.)
Line 35 will not compile.
Line36 will not compile.
Line 37 will not compile.
Line38 will not compile.
42. public class ClassA {43. public int getValue() {44. int value=0;45. boolean setting = true;46. String title=Hello;47. if (value || (setting title== Hello)) { return 1; }48. if (value == 1 title.equals(Hello)) { return 2; }49. }50. }And:70. ClassA a = new ClassA();71. a.getValue();What is the result?
1
2
Compilationfails.
Thecode runs with no output.
Anexception is thrown at runtime.
public class Test { publicstatic void main(String [] args) { intx =5; booleanb1 = true; booleanb2 = false; if((x==4) !b2) System.out.print(l); System.out.print(2); if((b2 = true) b1) System.out.print(3);}}What is the result?
2
3
1 2
2 3
1 2 3
Compilationfails.
Anexceptional is thrown at runtime.
10.int x=0;11.int y=10;12. do {13. y--;14. ++x;15. } while (x 5);16. System.out.print(x + , +y);What is the result?
5,6
5,5
6,5
6,6
11. public static void main(String[] args){12. for (int i=0;i= 10;i++){13. if( i6) break;14. }15. System.out.println(i);16. }Whatis the result?
6
7
10
11
Compilationfails.
An exception is thrown at runtime.
10. public class Bar {11.static void foo(int...x) {12. // insert code here13. }14. }Whichtwo code fragments, inserted independently at line 12, will allow the class tocompile? (Choose two.)
foreach(x)System.out.println(z);
for(int z : x) System.out.println(z);
while(x.hasNext()) System.out.println( x.next());
for(int i=0; i x.length; i++ ) System.out.println(x[i]);
public void go(){ Stringo = ; z: for(intx=0; x3; x++){ for(int y=0; y2; y++){ if(x== 1) break; if(x==2 y==1) break z; o= o + x + y; } } System.out.println(o);}Whatis the result when the go() method is invoked?
00
0001
000120
00012021
Compilationfails
Anexception is thrown at runtime
Which two code fragments correctly createand initialize a static arrayof int elements? (Choose two.)
staticfinal int[] a = { 100,200 };
static final int[] a;static{ a=new int[2]; a[0]=100; a[1]=200; }
staticfinal int[] a = new int[2] { 100,200 };
staticfinal int[] a;staticvoid init() { a = new int[3]; a[0]=100; a[1]=200; }
1. public class GC {2. private Object o;3. private void doSomethingElse(Object obj){ o = obj; }4. public void doSomething() {5. Object o = new Object();6. doSomethingElse(o);7. o = new Object();8. doSomethingElse(null);9. o=null;10. }11. }When the doSomething method is called,after which line does theObjectcreated in line 5 become available for garbage collection?
Line5
Line6
Line 7
Line 8
Line9
Line10
1. package com.company.application;2.3. public class MainClass {4. public static void main(String[] args) {} }And MainClass exists in the/apps/com/company/application directory.Assume the CLASSPATH environment variableis set to “.“ (current directory). Which two javacommands entered at thecommand linewillrun MainClass? (Choose two.)
javaMainClass if run from the /apps directory
javacom.company.application.MainClass if run from the /apps directory
java -classpath /appscom.company.application.MainClass if run from any directory
java -classpath . MainClass if run from the /apps/com/company/application directory
java -classpath /apps/com/company/application:. MainClass if run from the /appsdirectory
javacom.company.application.MainClass if run from the /apps/com/company/application directory
A developer is creating a class Book thatneeds to access class Paper.The Paper class is deployed in a JAR namedmyLib.jar. Which three,taken independently, will allow thedeveloper to use the Paper classwhile compiling the Book class? (Choosethree.)
TheJAR file is located at$JAVA_HOME/jre/classes/myLib.jar.
TheJAR file is located at $JAVA_HOME/jre/lib/ext/myLib.jar.
The JAR file is located at /foo/myLib.jarand aclasspath environment variable is set that includes /foo/myLib.jar/Paper.class.
The JAR file is located at /foo/myLib.jarand a classpath environment variable is set that includes/foo/myLib.jar.
TheJAR file is located at /foo/myLib.jar and the Book class is compiled using javac -cp/foo/myLib.jar/PaperBook.java.
TheJAR file is located at /foo/myLib.jar and the Book class is compiled usingjavac -d/foo/myLib.jar Book.java.
TheJAR file is located at /foo/myLib.jar and the Book class is compiled usingjavac -classpath/foo/myLib.jar Book.java.
Given the command line java Pass2 and:15. public class Pass2 {16. public void main(String [] args) {17. int x=6;18. Pass2 p = new Pass2();19. p.doStuff(x);20. System.out.print(” main x = “+ x);21. }22.23. void doStuff(int x) {24. System.out.print(” doStuffx = “+ x++);25. }26. }Whatis the result?
Compilation fails.
Anexception is thrown at runtime.
doStuffx = 6 main x = 6
doStuffx= 6 main x = 7
doStuffx= 7 main x = 6
doStuffx= 7 main x = 7
10. class Foo {11. private int x;12. public Foo(int x) {this.x=x; }13. public void setX( int x) { this.x = x;}14. public int getX() { return x; }15. }16.17. public class Gamma {18.19. static Foo fooBar( Foo foo) {20. foo = new Foo( 100);21. return foo;22. }23.24. public static void main( String[] args){25. Foo foo = new Foo( 300);26. System.out.print( foo.getX() + “-“);27.28. Foo fooFoo = fooBar( foo);29. System.out.print( foo.getX() + “-“);30. System.out.print( fooFoo.getX() + “-“);31.32. foo = fooBar( fooFoo);33. System.out.print( foo.getX() + “-“);34. System.out.prmt( fooFoo.getX());35. }36. }Whatis the output of this program?
300-100-100-100-100
300-300-100-100-100
300-300-300-100-100
300-300-300-300-100
11. static void test() throws Error {12. if (true) throw new AssertionError();13. System.out.print(”test “);14. }15. public static void main(String[] args){16. try { test(); }17. catch (Exception ex) { System.out.print(”exception “); }18. System.out.print(”end “);19. } What is the result?
end
Compilationfails.
exceptionend
exceptiontest end
A Throwable is thrown by main.
AnException is thrown by main.
10.class MakeFile {11.public static void main(String[] args) {12.try {13.File directory = new File(”d”);14.File file = new File(directory,”f”);15.if(!file.exists()) {16.file.createNewFile();17.}18.} catch (IOException e) {19. e.printStackTrace();20.}21.}22. }The current directory does NOT contain adirectory named “d.” Which three are true? (Choose three.)
Line16 is never executed.
Anexception is thrown at runtime.
Line13 creates a File object named “d.”
Line14 creates a File object named “f.’
Line13 creates a directory named “d” in the file system.
Line 16 creates a directory named “d” and afile ‘f’ within it in the file system.
Line14 creates a file named ‘f’ inside of the directory