24. What all gets printed when the following gets compiled and run. Select the two correct answers. 
public class test {
    public static void main(String args[]) { 
    String s1 = "abc";
    String s2 = new String("abc");   if(s1 == s2)
       System.out.println(1);
    else
        System.out.println(2);
    if(s1.equals(s2))
        System.out.println(3);
    else
        System.out.println(4);
    }
}
        
A. 1 
B. 2 
C. 3 
D. 4 请教大家,选什么?稍微解释一下就好 

解决方案 »

  1.   

    http://mcs.szu.edu.cn/user/zouzhxi/Article_38676
      

  2.   

    嗯,2楼..
    “=”是地址
    equal是值的比较
      

  3.   

    答案:B C
    如ls的==是比较地址的 S2 用new关键字在内存中重新划分了一块内存空间 他们的地址是不一样的。
    equal 是比较字符串的 会将S1与S2的字符一个个拿过来比较 你可以看下jdk帮助文档里面的equal方法的实现
      

  4.   

    2,3
    但是equals不是值的比较,是比较两个String对象相不相等,实现一个类,一般都要overrid实现eequals方法。
      

  5.   

    1和3
    C#中用==比较字符串相等,equals也是相同的比较内容
    这C#中没有比较对象相等的方法,比较应用的方法必须自己写.