《最新10月test.doc》由会员分享,可在线阅读,更多相关《最新10月test.doc(12页珍藏版)》请在金锄头文库上搜索。
1、1. Given:public class ReturnItReturnType methodA(byte x,double y)return (short)x/y*2;What is the valid return for methodA in line2?A. int B. byte C. long D. short E. float F. doubleF2. Given:abstract class AbstractItabstract float getFloat();public class AbstractTest extends AbstractItprivate float
2、f1 = 1.0f;private float getFloat()retrun f1;What is the result?A. Compilation is successfulB. An error on line 6 causes a runtime failureC. An error at line 6 causes compilation to failD. An error at line 2 causes compilation to failC3. Which declaration prevents creating a subclass of an outer clas
3、s?A. static class FooBarB. private class FooBarC. abstract class FooBarD. final public class FooBarE. final abstract class FooBarD4. Given:byte array1,array2;byte array3;byte array4;if each array has been initialized, which statement will cause a compiler error?A. array2 = array1B. array2=array3C. a
4、rray2=array4D. both A and BE. both A and CF. both B and CA5.public class Testpublic int aMethod()static int i=0;i+;return i;public static void main(String args)Test test = new Test();test.aMethod();int j=test.aMethod();System.out.println(j);What is the result?A. Compilation will failB. Compilation w
5、ill succeed and the program will print”0”.C. Compilation will succeed and the program will print”1”.D. Compilation will succeed and the program will print”2”.A6.You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access modifier that will accom
6、plisher this objective?A. public B. private C. protectedD. transientE. No access modifier is qualifiedC7.class Superpublic int i=0;public Super(String text)i=1;public class Sub extends Superpublic Sub(String text)i=2;public static void main(String ag)Sub sub=new Sub(“Hello”);System.out.println(sub.i
7、);What is the result?A. Compilation will failB. Compilation will succeed and the program will print”0”.C. Compilation will succeed and the program will print”1”D. Compilation will succeed and the program will print”2”A8. Given:class Superpublic float getNum()return 3.0f;public class Sub extends Supe
8、rWhich method , placed at line 6,will cause a complier error?A. public float getNum()return 4.0f;B. public void getNum()C. public void getNum(double d)D. public double getNum(float d)return 4.0d;B9. public class Testpublic static void main(String args)int i=0;while(1)if(i=4)break;i+;What is the valu
9、e of i at line 10?A. 0 B. 3 C. 4 D. 5 E. The code will not compileE10.Given:int i=1,j=10;doif(i+-j) continue;while(i5);After execution, what are the values for i and j?A. i=6 and j=5B. i=5 and j=5C. i=6 and j=4D. i=5 and j=6E. i=6 and j=6D11.Given:public class IfElsepublic static void main(String ar
10、gs)if(odd(5)System.out.println(“odd”);elseSystem.out.println(“Even”);public static int odd(int x)return x%2;What is the result?A. The output is odd;B. The output is even;C. An error on line 3 causes compilation to failD. An error on line 8 causes compilation to failC12import java.io.IOException;publ
11、ic class ExceptionTestpublic static void main(String args)trymethodA();catch(IOException e)System.out.println(“Caught IOException”);catch(Exception e)System.out.println(“Caught Exception”);public static void methodA()throw new IOException();What is the result?A. The code will not compile;B. The outp
12、ut is Caught ExceptionC. The output is Caught IOExceptionD. The program executes normally without printing a messageA13public class Testpublic static String output = “”;public static void foo(int i)tryif(i=1)throw new Exception();output += “1”;catch(Exception e)output += “2”;return;finallyoutput +=
13、“3”;output += “4”;public static void main(String args)foo(0);foo(1);What is the value of the variable output at line 24?Shortanswer:1342314.Given:public class Foopublic static void main(String args)tryreturn;finallySystem.out.println(“Finally”);What is the result?A. The program runs and prints nothi
14、ng.B. The program runs and prints “Finally”;C. The code compiles, but an exception is thrown at runtime.D. The code will not compile because the catch block is missing.B15.Given public class IfTestpublic static void main(String s)int x=3;int y=1;if(x=y)System.out.println(“Not equal”);elseSystem.out.println(“Equal”);What is t