企业面试题(附答案)(4)

2019-01-07 16:52

E. The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=2, y=2”)

解答:E

多线程共享相同的数据,使用synchronized实现数据同步。

35、Which two CANNOT directly cause a thread to stop executing? (Choose Two) A. Existing from a synchronized block. B. Calling the wait method on an object. C. Calling notify method on an object.

D. Calling read method on an InputStream object. E. Calling the SetPriority method on a Thread object. 解答:AD

stop方法.这个方法将终止所有未结束的方法,包括run方法。当一个线程停止时候,他会立

即释

放 所有他锁住对象上的锁。这会导致对象处于不一致的状态。 当线程想终止另一

个线程的时

候,它无法知道何时调用stop是安全的,何时会导致对象被破坏。所以这个方法被弃

用了。你应

该中断一个线程而不是停止他。被中断的线程会在安全的时候停止。

36、 Which two statements are true regarding the creation of a default constructor?

(Choose Two) A. B. C.

The default constructor initializes method variables.

The default constructor invokes the no-parameter constructor of the superclass. The default constructor initializes the instance variables declared in the class. D.

If a class lacks a no-parameter constructor,, but has other constructors, the compiler creates a default constructor. E.

The compiler creates a default constructor only when there are no other constructors for the class. 解答:CE

构造方法的作用是实例化对象的时候给数据成员初始化,如果类中没有显示的提供构造方法,

系统会提供默认的无参构造方法,如果有了其它构造方法,默认的构造方法不再提供。 37、 Given:

public class OuterClass { private double d1 = 1.0; //insert code here }

You need to insert an inner class declaration at line2. Which two inner class

declarations are valid? (Choose Two) A. B. C. D. E.

static class InnerOne { public double methoda() {return d1;} } static class InnerOne { static double methoda() {return d1;} } private class InnerOne { public double methoda() {return d1;} } protected class InnerOne { static double methoda() {return d1;} } public abstract class InnerOne { public abstract double methoda(); }

解答:CE

AB.内部类可以声明为static的,但此时就不能再使用外层封装类的非static的成员变量; D.非static的内部类中的成员不能声明为static的,只有在顶层类或static的内部类中 才可声明static成员

38、 Which two declarations prevent the overriding of a method? (Choose Two) A. final void methoda() {} B. void final methoda() {} C. static void methoda() {} D. static final void methoda() {} E. final abstract void methoda() {} 解答:AD

final修饰方法,在子类中不能被重写。 39、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. B. C.

Compilation will fail.

Compilation will succeed and the program will print “3”

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. 解答:B

局部内部类的使用 40、 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” 解答:D

采用String foo = “blue”定义方式定义的字符串放在字符串池中,通过String bar = foo; 他们指向了同一地址空间,就是同一个池子,当执行foo = “green”; foo指向新的地址

空间。

41、Which code determines the int value foo closest to a double value bar? A. int foo = (int) Math.max(bar); B. int foo = (int) Math.min(bar); C. int foo = (int) Math.abs(bar); D. int foo = (int) Math.ceil(bar); E. int foo = (int) Math.floor(bar); F. int foo = (int) Math.round(bar); 解答:DEF

A B两个选项方法是用错误,都是两个参数。 abs方法是取bar的绝对值,

ceil方法返回最小的(最接近负无穷大)double 值,该值大于等于参数,并等于某个整数。 floor方法返回最大的(最接近正无穷大)double 值,该值小于等于参数,并等于某个整数。 round方法 返回最接近参数的 long。 42、 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. 解答:B

类MyVector不能是私有的 43、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 解答:C


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

下一篇:2017年电大学前游戏理论与指导形成性考核册答案

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

马上注册会员

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