新版面试题 - 无答案(2)

2019-09-01 13:03

16.Given:

public class OuterClass {

private double d1 = 1.0; //insert code here

}

Which two inner class declarations are valid? ( )

A. static class InnerOne { public double methoda() {return d1;} } B. static class InnerOne { static double methoda() {return d1;} } C. private class InnerOne { public double methoda() {return d1;} } D. protected class InnerOne { static double methoda() {return d1;} } E. public abstract class InnerOne { public abstract double methoda(); }

17.Which two declarations prevent the overriding of a method? ( ) A. final void methoda() {} B. void final methoda() {} C. static void methoda() {} D. static final void methoda() {} E. final abstract void methoda() {} 18.Given:

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.println(foo.i);

}

}

What is the result? A. Compilation will fail.

B. Compilation will succeed and the program will print “3”

C. Compilation will succeed but the program will throw a ClassCastException at line 6. D. Compilation will succeed but the program will throw a ClassCastException at line 7.

19.Given:

public class Test { public static void main (String [] args){ String foo = “blue”;

String bar = foo; foo = “green”;

System.out.println(bar);

}

}

What is the result?

A. An exception is thrown. B. The code will not compile. C. The program prints “null” D. The program prints “blue” E. The program prints “green”

20.Exhibit:

1. package foo;

2. import java.util.Vector;

3. private class MyVector extends Vector { 4. int i = 1;

5. public MyVector(){ 6. i = 2; 7. } 8. }

9. public class MyNewVector extends MyVector { 10. public MyNewVector(){ 11. i = 4; 12. }

13. public static void main (String args []){ 14. MyVector v = new MyNewVector(); 15. } 16. }

The file MyNewVector.java is shown in the exhibit. What is the result? A. Compilation will succeed.

B. Compilation will fail at line 3. C. Compilation will fail at line 6. D. Compilation will fail at line 9. E. Compilation will fail at line 14.

21.Given:

public class Test {

public static void main (String[]args) {

String foo = args[1];

String bar = args[2];

String baz = args[3]; System.out.println(“baz = ” + baz);

}

}

And the output: Baz = 2

Which command line invocation will produce the output? A. java Test 2222 B. java Test 1 2 3 4 C. java Test 4 2 4 2 D. java Test 4 3 2 1

22.Given:

public class foo {

static String s;

public static void main (String[]args) {

System.out.println (“s=” + s);

}

}

What is the result?

A. The code compiles and “s=” is printed. B. The code compiles and “s=null” is printed.

C. The code 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.

23.Given:

public class ExceptionTest { class TestException extends Exception {}

public void runTest () throws TestException {} public void test (){ /* Point X*/

runTest ();

}

}

At point X on line 4, which code can be added to make the code compile? A. throws Exception B. Catch (Exception e). C. Throws RuntimeException. D. Catch (TestException e). E. No code is necessary.

24.在下面程序的第 6 行补充上下列哪个方法,会导致在编译过程中发生错误? 1) class Super{

2) public float getNum(){ 3) return 3.0f; 4) } 5) }

6) pubhc class Sub extends Super{ 7) 8) }

A.public float getNum(){retun 4.0f;} B.public void getNum(){}

C.public void getNum(double d){}

D.public double getNum(float d){ retun 4.0f ;}

25.关于 java.lang.String 类,以下描述正确的一项是( A. String 类是 final 类故不可以继承; B. String 类是 final 类故可以继承; C. String 类不是 final 类故不可以继承;

D. String 类不是 final 类故可以继承;

26.接口是 Java 面向对象的实现机制之一,以下说法正确的是:( A. Java 支持多重继承,一个类可以实现多个接口; B. Java 只支持单重继承,一个类可以实现多个接口; C. Java 只支持单重继承,一个类只可以实现一个接口; D. Java 支持多重继承,但一个类只可以实现一个接口。

27.下列关于 interface 的说法正确的是:( ) A. interface 中可以有 private 方法 B. interface 中可以有 final 方法

)

C. interface 中可以有 function 实现 D. interface 可以继承其他 interface

28.已知 A 类被打包在 packageA,B类被打包在packageB且B类被声明为public,且有一个成员变量 x 被声明为,protected 控制方式C类也位于packageA包且继承了B类。则以下说话正确的是( ) A. A 类的实例不能访问到 B 类的实例

B. A 类的实例能够访问到 B 类一个实例的 x 成员 C. C 类的实例可以访问到 B 类一个实例的 x 成员 D. C 类的实例不能访问到 B 类的实例

29.以下程序正确的输出是( )

package test;

public class FatherClass {

public FatherClass() {

System.out.println(\}

}

package test;

import test.FatherClass;

public class ChildClass extends FatherClass { public ChildClass() { System.out.println(\

}

public static void main(String[] args) {

FatherClass fc = new FatherClass();

ChildClass cc = new ChildClass(); }

}

A.FatherClass Create FatherClass Create ChildClass Create B.FatherClass Create ChildClass Create FatherClass Create C.ChildClass Create ChildClass Create FatherClass Create D.ChildClass Create FatherClass Create FatherClass Create

30.题目:

1. public class test{

2. public static void main (String args[]) { 3. int i = 0xFFFFFFF1; 4. int j = ~i; 5. } 6. }

程序运行到第 5 行时,j 的值为多少?( ) A. –15 B. 0 C. 1 D. 14

E. 在第三行的错误导致编译失败

31.关于 sleep()和 wait(),以下描述错误的一项是( )

A. sleep 是线程类(Thread)的方法,wait 是 Object 类的方法; B. sleep 不释放对象锁,wait 放弃对象锁;

C. sleep 暂停线程、但监控状态仍然保持,结束后会自动恢复;

D. wait 后进入等待锁定池,只有针对此对象发出 notify 方法后获得对象锁进入运行状态。

32.下面能让线程停止执行的有( ) A. sleep(); B. stop(); C. notify(); D. synchronized(); E. yield(); F. wait();

G. notifyAll();

33.不能用来修饰 interface 的有( ) A.private B.public C.protected D.static


新版面试题 - 无答案(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:中菲南海争端之五方礁事件 - 图文

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: