资源预览内容
第1页 / 共12页
第2页 / 共12页
第3页 / 共12页
第4页 / 共12页
第5页 / 共12页
第6页 / 共12页
第7页 / 共12页
第8页 / 共12页
第9页 / 共12页
第10页 / 共12页
亲,该文档总共12页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
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 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 class?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. array2=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 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”.A6.You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access modifier that will accomplisher 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);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 SuperWhich 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 value 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 args)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;public 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 output 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 += “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 nothing.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
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号