有感于Java Final Exam

秋季学期的java已经结课了,当看到教务平台贴出的通知说考试形式为单选题时,心中喜忧参半。

可喜的是这种考试形式还是比较得民心,毕竟除了判断题,最好做的也就是单选题了。

然而期中考试选择题50%的命中率还历历在目,不免心生忧虑。然后后来的事实证明,果然我的忧虑不是毫无道理的,再次被虐,而且被虐的毫无怨言。

考试完后把还有印象的几道题目在eclipse上跑了跑,结果也是不堪回首。。。。

然后我决定把它们记下来,以期在不远的将来能够一雪前耻。

#1.对,你没有看错,就是这道题,我当时靠着卓越的逆向思维一口咬定答案是11,结果。。正解12.

public class Testexam {
    public static void main(String[] args) {
        
        long i = Math.round(11.5);
        System.out.println(i);
        
    }

}

 #2.  以下哪个类没有重写toString()方法和hashCode()方法。 String Double Character StringBuffer

我选择了Double类,事实上,Double类重写了上述方法,StringBuffer类没有重写。

 1 public class Testexam {
 2     public static void main(String[] args) {
 3         
 4         Double d1 = 123.45;
 5         Double d2 = 123.45;
 6         boolean flag = d1.equals(d2);
 7         System.out.println(flag);
 8         
 9     }
10 
11 }

 #3 下列程序输出的结果是什么?(知识点确实很模糊,不清楚)

 1 public class Testexam {
 2     public static void main(String[] args) {
 3         
 4         String s1 = new String("a");
 5         s1 = s1 + "b";
 6         System.out.println(s1 == "ab");//false
 7         String s2 = "a" + "b";
 8         System.out.println(s2 == "ab");//true
 9     }
10 
11 }

#4 char类型的取值范围。。。。就记得char是两个字节,16位,毫不犹豫的选了 -65536-65535 , 事实证明任何不经过思考的决定都是荒唐的。 正解 0 - 65535

#5 以下程序的运行结果:

public class test extends Thread{

    public static void main(String[] args) {    
        
        Thread t = new Thread();
        t.start();
        System.out.println("one");
        t.start();
        System.out.println("two");
        
    }
    
    public void run() {
        System.out.println("Thread");
    }

}

 正确答案是程序运行的过程中会抛出一个异常, 而不是我选择的编译错误(Complie fail)。

原文地址:https://www.cnblogs.com/beyond-Acm/p/4113865.html