新版面试题 - 无答案

2019-09-01 13:03

一. 选择题(155)

1.下面中哪两个可以在 A 的子类中使用:( )

class A {

protected int method1 (int a, int b) {

return 0;

}

}

A. public int method 1 (int a, int b) { return 0; } B. private int method1 (int a, int b) { return 0; } C. private int method1 (int a, long b) { return 0; } D. public short method1 (int a, int b) { return 0; }

2.What will be the output when you compile and execute the following program. class Base{

void test() {

System.out.println(\

}

}

public class Child extends Base {

void test() {

System.out.println(\

}

public static void main(String[]

a){ Child anObj = new Child();

Base baseObj = (Base)anObj;

baseObj.test();

}

}

Select most appropriate answer.( ) A.Child.test() Base.test() B.Base.test()

Child.test() C.Base.test() D.Child.test()

3.What will be the output when you compile and execute the following program.

class Base{

static void test(){

System.out.println(\ } }

public class Child extends Base { void test(){ System.out.println(\ Base.test(); //Call the parent method }

public static void main(String[] a) { new Child().test(); } }

Select most appropriate answer. ( ) A.Child.test() Base.test() B.Child.test() Child.test()

C.Compilation error. Cannot override a static method by an instance method D.Runtime error. Cannot override a static method by an instance method

4.What will be the output when you compile and execute the following program. The symbol ’ ?’ means space.

1:public class Base{ 2:

3: private void test() { 4:

5: String aStr = \? One? \ 6: String bStr = aStr; 7: aStr.toUpperCase();

8: aStr.trim();

9: System.out.println(\ 7: } 8:

9: public static void main(String[] a) { 10: new Base().test(); 11: }

12: }

Select most appropriate answer.( ) A.[ONE,? One? ] B.[? One? ,One] C.[ONE,One] D.[ONE,ONE]

E.[? One? ,? One? ]

5.下面关于变量及其范围的陈述哪些是不正确的( A.实例变量是类的成员变量 B.实例变量用关键字 static 声明

C.在方法中定义的局部变量在该方法被执行时创建 D.局部变量在使用前必须被初始化

6.编译运行以下程序后,关于输出结果的说明正确的是 (

):

public class Conditional{

public static void main(String args[]){

int x=4;

System.out.println(“value is “+ ((x>4) ? 99.9 :9)); } }

A. 输出结果为:value is 99.99 B. 输出结果为:value is 9 C. 输出结果为:value is 9.0 D. 编译错误

7.关于以下 application 的说明,正确的是( ):

1. class StaticStuff{

2. static int x = 10; 3. static { 4. x += 5; 5. }

6. public static void main(String[] args){ 7. System.out.println(“x = ” + x); 8. }

9. static{ 10. x /= 3; 11. } 12. }

A、 4 行与 9 行不能通过编译,因为缺少方法名和返回类型 B、 9 行不能通过编译,因为只能有一个静态初始化器 C、 编译通过,执行结果为:x=5

D、 编译通过,执行结果为:x=3

8.关于以下程序代码的说明正确的是( ): 1.class HasStatic{

2. private static int x=100;

3. public static void main(String args[]){ 4. HasStatic hs1 = new HasStatic(); 5. hs1.x++; 6. HasStatic hs2 = new HasStatic(); 7. hs2.x++; 8. hs1 = new HasStatic(); 9. hs1.x++;

10. HasStatic.x--;

11. System.out.println(“x=”+x); 12. } 13.}

A、5 行不能通过编译,因为引用了私有静态变量 B、10 行不能通过编译,因为 x 是私有静态变量 C、程序通过编译,输出结果为:x=103 D、程序通过编译,输出结果为:x=102

9.下列哪种说法是正确的( )

A.实例方法可直接调用超类的实例方法 B.实例方法可直接调用超类的类方法 C.实例方法可直接调用其他类的实例方法 D.实例方法可直接调用本类的类方法

10.下面代码的执行结果是? import java.util.*;

public class ShortSet{

public static void main(String args[]){

Set s=new HashSet(); for(Short i=0;i<100;i++){ s.add(i);

s.remove(i-1); }

System.out.println(s.size());

} } A.1 B.100

C.Throws Exception D.None of the Above

11.执行下列代码String[] s=new String[10];后,哪个结论是正确的 ( ) A. s[9] 为 null; B. s[10] 为 \ C. s[0] 为 未定义 D. s.length 为 10 12.栈是一种( )。 A.存取受限的线性结构 B.存取不受限的线性结构 C.存取受限的非线性结构 D.存取不受限的非线性结构 13.Given:

public static void main(String[] args) {

Object obj = new Object() {

public int hashCode() { return 42; }

};

System.out.println(obj.hashCode()); }

What is the result? A. 42

B. An exception is thrown at runtime.

C. Compilation fails because of an error on line 12. D. Compilation fails because of an error on line 16. E. Compilation fails because of an error on line 17. 14.Given:

public class Test {

public static void main(String[] args) {

String str = NULL; System.out.println(str);

}

}

What is the result? A. NULL

B. Compilation fails.

C. The code runs with no output. D. An exception is thrown at runtime.

15、Exhibit:

1.public class X implements Runnable { 2. private int x; 3. private int y;

4. public static void main(String [] args) { 5. X that = new X(); 6. (new Thread(that)).start(); 7. (new Thread(that)).start(); 8. }

9. public synchronized void run( ){ 10. for (;;) { 11. x++; 12. y++; 13. System.out.println(“x = “ + x + “, y = “ + y); 14. } 15. } 16.}

What is the result?

A. An error at line 11 causes compilation to fail. B. Errors at lines 7 and 8 cause compilation to fail.

C. The program prints pairs of values for x and y that might not always be the same on the

same line (for example, “x=2, y=1”) D. 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=1, y=1”) 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”)


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

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

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

马上注册会员

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