1、1一Which two demonstrate an “is a” relationship? (Choose Two) A. public interface Person /语法错了public class Employee extends Person B. public interface Shape /语法错了public class Employee extends Sha pe C. public interface Color /语法错了public class Employee extends Color D. public class Species public clas
2、s Animalprivate Species species;E. interface Component Class Container implements Component (Private Component children;二which statement is true? A. An anonymous inner class may be declared as final B. An anonymous inner class can be declared as private C. An anonymous inner class can implement muti
3、ple interfaces D. An anonymous inner class can access final variables in any enclosing scope (不能)E. Construction of an instance of a static inner class requires an instance of the encloing outer class 构造一个静态的内部类对象需要构造包含它的外部类的对象三. Given:1. package foo;2. 3. public class Outer (4. public static class
4、Inner (5. )6. )Which statement is true? A. An instance of the Inner class can be constructed with “new Outer.Inner ()”B. An instance of the inner class cannot be constructed outside of package foo他们都是 public 的,只要在外部 import 就行2C. An instance of the inner class can only be constructed from within the
5、outer classD. From within the package bar, an instance of the inner class can be constructed with “new inner()”四Exhibit(展览、陈列):1 public class enclosinggone2 public class insideone3 4 public class inertest5 public static void main (String args)6 enclosingone eo = new enclosingone();7 /insert code her
6、e8 Which statement at line 7 constructs an instance of the inner class?A. InsideOne ei = eo.new InsideOne(); 写程序试出来B. Eo.InsideOne ei = eo.new InsideOne();C InsideOne ei = EnclosingOne.new InsideOne();D.EnclosingOne InsideOne ei = eo.new InsideOne();五 1) interface Foo 2) int k=0; 3) 4) public class
7、Test implements Foo 5) public static void main(String args) 6) int i; 7) Test test =new Test(); 8) i=test.k; 9) i=Test.k; 10) i=Foo.k; 11) 12) 3What is the result? A. Compilation succeeds.B. An error at line 2 causes compilation to fail.C. An error at line 9 causes compilation to fail.D. An error at
8、 line 10 causes compilation to fail.E. An error at line 11 causes compilation to fail.六 /point X public class Foo public static void main(String args) PrintWriter out=new PrintWriter(new java.io.OutputStreamWriter(System.out),true); out.println(“Hello“); which statement at point X on line 1 allows t
9、his code to compile and run? 在 point X 这个位置要填入什么代码才能使程序运行A.import java.io.PrintWriter B.include java.io.PrintWriter C.import java.io.OutputStreamWriter D.include java.io.OutputStreamWriter E.No statement is needed 本来两个都要 import,但是后者 OutputStreamWriter 指定了包结构java.io.OutputStreamWriter七 what is reserv
10、ed words in java? 保留字而非关键字A. run B. default C. implement D. import 八. which three are valid declaraction of a float? (float 作为整数是可以的,其余几个都是 double)A. float foo=-1; B. float foo=1.0; 4C. float foo=42e1; D. float foo=2.02f; E. float foo=3.03d; F. float foo=0x0123; 九. Given:8. int index = 1;9. boolean
11、test = new boolean3; (数组作为对象缺省初始化为 false)10. boolean foo= test index;What is the result? A. foo has the value of 0B. foo has the value of nullC. foo has the value of trueD. foo has the value of falseE. an exception is thrownF. the code will not compile十. Given:1. public class test(2. public static v
12、oid main(Stringargs)3. String foo = args 1;4. String foo = args 2;5. String foo = args 3;6. 7. And the command line invocation:Java Test What is the result? A. baz has the value of “”B. baz has the value of nullC. baz has the value of “red”D. baz has the value of “blue”5E. bax has the value of “gree
13、n”F. the code does not compileG. the program throws an exception(此题题目出错了,重复定义了变量 foo,如果没有重复的话,应选 G,因为只传递了 0-2 三个数组元素,而题目中需要访问 args 3,所以会抛出数组越界异常)十一. int index=1; int foo=new int3; int bar=fooindex; /bar=0int baz=bar+index; /baz=1what is the result? A. baz has a value of 0 B. baz has value of 1 C. ba
14、z has value of 2 D. an exception is thrown E. the code will not compile 十二. 1)public class Foo 2) public static void main(String args) 3) String s; 4) System.out.println(“s=“+s); 5) 6) what is the result? A. The code compiles and “s=” is printed.B. The code compiles and “s=null” is printed.C. The co
15、de does not compile because string s is not initialized. D. The code does not compile because string s cannot be referenced.E. The code compiles, but a NullPointerException is thrown when toString is called.6十三. Which will declare a method that forces a subclass to implement it? (谁声明了一个方法,子类必须实现它)A.
16、 public double methoda();B. static void methoda (double d1) C. public native double methoda();D. abstract public void methoda();E. protected void methoda (double d1)十四. You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access modifier that wi
17、ll accomplish this objective?(你希望子类在任何包里都能访问父类,为完成这个目的,下列哪个是最严格的访问权限)A. PublicB. PrivateC. ProtectedD. TransientE. No access modifier is qualified十五. Given:1. abstract class abstrctIt 2. abstract float getFloat ();3. )4. public class AbstractTest extends AbstractIt 5. private float f1= 1.0f;6. priva
18、te float getFloat () return f1;7. What is the result?A. Compilation is successful.B. An error on line 6 causes a runtime failure.(抛出实时异常)C. An error at line 6 causes compilation to fail.D. An error at line 2 causes compilation to fail.(子类覆盖父类方法的时候,不能比父类方法具有更严格的访问权限)7十六. Click the exhibit button:1. p
19、ublic class test2. public int aMethod()3. static int i=0; 4. i+; 5. return I; 6. 7. public static void main (String args) 8. test test = new test(); 9. test.aMethod(); 10. int j = test.aMethod(); 11. System.out.printIn(j); 12. 13. (局部变量不能声明为静态) What is the result? A. Compilation will fail.B. Compila
20、tion 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”.十七.1) class Super 2) public float getNum()return 3.0f; 3) 4) 5) public class Sub extends Super 6) 7) which method, placed at line 6,
21、will cause a compiler error? A. public float getNum()return 4.0f; B. public void getNum() 返回值类型不同不足以构成方法的重载8C. public void getNum(double d) D. public double getNum(float d)return 4.0d; 十八. Which declaration prevents creating a subclass of an outer class? A.static class FooBar B.pivate class Foobar C
22、.abstract class FooBar D.final public class FooBar E.final abstract class FooBar 抽象类不能声明为 final十九. byte array1,array2 byte array3 byte array4 if each has been initialized, which statement will cause a compile error? A. array2 = array1;B. array2 = array3;C. array2 = array4;D. both A and BE. both A an
23、d CF. both B and C(一维数组和二维数组的区别)二十. class Super public int i=0; public Super(String text) i=1; public class Sub extends Super public Sub(String text) i=2; public static void main(String args) Sub sub=new Sub(“Hello“); 9System.out.println(sub.i); what is the result? A. compile will fail B. compile success and print “0“ C. compile success and print “1“ D. compile success and print “2“ 子类总要去调用父类的构造函数,有两种调用方式,自动调用(无参构造函数),主动调用带参构造函数。