<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 26  文章 - 2  trackbacks - 0
    <2011年10月>
    2526272829301
    2345678
    9101112131415
    16171819202122
    23242526272829
    303112345

    常用鏈接

    留言簿

    隨筆檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    總結
    1、= =操作符比較的是操作符兩端的操作數(shù)是否是同一個對象;另外= =操作符兩邊的操作數(shù)必須是同一類型的(可以是父子類之間)才能編譯通過。
    2、String的equals()方法比較的是兩個String對象的內容是否一樣
    3、= =比較的是地址,如果是具體的阿拉伯數(shù)字的比較,值相等則為TRUE,如:
    int a=10 與 long b=10L 與 double c=10.0都是相同的(為true),因為他們都指向地址為10的堆棧;如下題111;
    ? String s= "hello";
    String t = "hello";
    char c[] = {'h','e','l','l','o'} 
    Which return true?
    A. s.equals(t);
    B. t.equals(c);
    C. s==t;
    D. t.equals(new String("hello"));
    E. t==c.
    答案:(acd)
    題目:哪些返回true。
    這個在前面第10題的equals()方法和==操作符的討論中論述過。==操作符比較的是操作符兩端的操作數(shù)是否是同一個對象,而String的equals()方法比較的是兩個String對象的內容是否一樣,其參數(shù)是一個String對象時才有可能返回true,其它對象都返回假。需要指出的是由于s和t并非使用new創(chuàng)建的,他們指向內存池中的同一個字符串常量,因此其地址實際上是相同的(這個可以從反編譯一個簡單的測試程序的結果得到,限于篇幅不列出測試代碼和反編譯的分析),因此答案c也是正確的。

     Given the following class:
    public class Sample{
    long length;
    public Sample(long l){ length = l; }
    public static void main(String arg[]){
    Sample s1, s2, s3;
    s1 = new Sample(21L);
    s2 = new Sample(21L); 
    s3 = s2;
    long m = 21L;
    }
    }
    Which expression returns true?
    A. s1 == s2;
    B. s2 == s3;
    C. m == s1;
    D. s1.equals(m).
    答案:(b)//D不對,只有String的equals()方法才比較值;
    題目:給出下面的類:  …
    哪個表達式返回true。
    前面已經(jīng)敘述過==操作符和String的equals()方法的特點,另外==操作符兩邊的操作數(shù)必須是同一類型的(可以是父子類之間)才能編譯通過。

    再看以下幾道
     17. float f=4.2F; 
    Float g=new Float(4.2F); 
    Double d=new Double(4.2); 
    Which are true? 
    A. f= =g   B. g= =g   C. d= =f   D. d.equals(f)  E d.equals(g)  F. g.equals(4.2); 
    答案:B
    ? 93. Click the exhibit button:
    1. public class X { 
    2. public static void main (String[]args)  { 
    3. String s1 = new String (“true”); 
    4. Boolean b1 = new Boolean (true); 
    5. if (s2.equals(b1))   { 
    6. System.out.printIn(“Equal”);
     7.       } 8.      } 9.     }   
    What is the result?
    A. The program runs and prints nothing.
    B. The program runs and prints “Equal.”
    C. An error at line 5 causes compilation to fail.
    D. The program runs but aborts with an exception.
    答案:A

    比較下題,小心使用equals 和 = =的區(qū)別;
    ? 93. Click the exhibit button:
    1. public class X { 
    2. public static void main (String[]args)  { 
    3. String s1 = new String (“true”); 
    4. Boolean b1 = new Boolean (true); 
    5. if (s2 = = b1) { //= =操作符兩邊的操作數(shù)必須是同一類型的(可以是父子類之間)才能編譯通過
    6. System.out.printIn(“Equal”);
     7.       } 8.      } 9.     }   
    What is the result?
    A. The program runs and prints nothing.
    B. The program runs and prints “Equal.”
    C. An error at line 5 causes compilation to fail.
    D. The program runs but aborts with an exception.
    答案:C
    ? 111. Given:
    1. public class Foo {
    2. private int val;
    3. public foo(int v) (val = v;)  }
    4. public static void main (String [] args)  {
    5. Foo a = new Foo (10);
    6. Foo b = new Foo (10);
    7. Foo c = a;
    8. int d = 10;
    9. double e = 10.0;
    10. }
    11. }
    Which three logical expressions evaluate to true? (Choose Three)  
    A.(a ==c)
    B.(d ==e)
    C.(b ==d)
    D.(a ==b)
    E.(b ==c)
    F.(d ==10.0)
    答案:ABF //= =比較的是地址,他們都指向地址為10的堆棧;

    Given the following code, what test would you need to put in place of 
    the comment line? 
    //place test here to result in an output of the string Equal 
    public class EqTest{
      public static void main(String argv[]){
       EqTest e=new EqTest();
      }

     EqTest(){
       String s="Java";
       String s2="java";//小心大小寫
       //place test here {
        System.out.println("Equal");
        }else
        {
        System.out.println("Not equal");
       }
      }
    }
    1) if(s==s2) 
    2) if(s.equals(s2) 
    3) if(s.equalsIgnoreCase(s2)) 
    4)if(s.noCaseMatch(s2))
    答案:3)//小心大小寫

    posted on 2011-10-08 16:36 Java_liyadong 閱讀(6379) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 成人婷婷网色偷偷亚洲男人的天堂| 中文字幕亚洲天堂| a级毛片无码免费真人久久| 免费一看一级毛片| 男男gay做爽爽的视频免费| 免费国产a理论片| 免费国产a国产片高清| 特级毛片aaaa级毛片免费| 国产免费变态视频网址网站| 亚洲AV成人无码网天堂| 亚洲AV无码不卡在线观看下载 | 少妇中文字幕乱码亚洲影视| 国产一级片免费看| 97久久精品亚洲中文字幕无码| 最近免费中文字幕大全免费版视频| 亚洲精品福利网站| 午夜小视频免费观看| 精品一区二区三区免费毛片| 亚洲色图综合在线| 久久香蕉国产线看免费| 亚洲人成电影青青在线播放| 国产免费伦精品一区二区三区| 中文字幕人成人乱码亚洲电影| 久久精品成人免费观看| 亚洲五月综合缴情婷婷| 国产人妖ts在线观看免费视频| 中文字幕在线免费视频| 亚洲精品韩国美女在线| 在线观看国产情趣免费视频| h视频在线免费观看| 亚洲欧洲中文日产| 国产一区二区免费在线| 暖暖免费在线中文日本| 亚洲免费人成视频观看| 亚洲 另类 无码 在线| 亚洲欧洲另类春色校园网站| 免费永久在线观看黄网站| 日本人成在线视频免费播放| 亚洲砖码砖专无区2023| 国产啪亚洲国产精品无码| 国产成人免费高清激情明星|