牛客网刷题选择题5

1,

public class IfTest{

    public static void main(string[]args){

        int x=3;

        int y=1;

        if(x=y)

            System.out.println(“Not equal”);

        else

            System.out.println(“Equal”);

     }

}

What is the result?

A The output is “Equal”

B The output in “Not Equal”

C An error at line 5 causes compilation to fall.

D The program executes but does not print a message.

答案是:C

2, 下列不正确的 Java 语言标识符是( )

A Sky

B $Computer

C for

D NULL

解析:C

3,假设如下代码中,若t1线程在t2线程启动之前已经完成启动。代码的输出是()

public static void main(String[]args)throws Exception {
    final Object obj = new Object();
    Thread t1 = new Thread() {
        public void run() {
            synchronized (obj) {
                try {
                    obj.wait();
                    System.out.println("Thread 1 wake up.");
                } catch (InterruptedException e) {
                }
            }
        }
    };
    t1.start();
    Thread.sleep(1000);//We assume thread 1 must start up within 1 sec.
    Thread t2 = new Thread() {
        public void run() {
            synchronized (obj) {
                obj.notifyAll();
                System.out.println("Thread 2 sent notify.");
            }
        }
    };
    t2.start();

 A  Thread 1 wake up Thread 2 sent notify.

Thread 2 sent notify. Thread 1 wake up

C A、B皆有可能

D 程序无输出卡死

解析:B 

4,@SuppressWarnings(“deprecation”)的功能是什么?

A 屏蔽不赞同使用的类和方法的警告

B 屏蔽在强制类型转换的时候编译器给出的警告

C 关闭所有警告信息

D 当在可序列化的类上缺少serialVersionUID定义的警告

解析:A  

猜你喜欢

转载自blog.csdn.net/qq_37244548/article/details/107496077