【Object类equals方法联系】 看下列程序,不运行说结果,写出答案后,并在IntelliJ IDEA中运行看看自己给的答案与运行结果是否正确,并分析原因。

public class Test03 {
    public static void main(String[] args) {
     /*   String s1 = new String("ABC");
        String s2 = "ABC";
        System.out.println(s1==s2);//false
        System.out.println(s1.equals(s2));//true

        System.out.println("2==============");
        String s3 = "abc";
        String s4 = "abc";
        System.out.println(s3 == s4);//true
        System.out.println(s3.equals(s4));//true

        System.out.println("3==============");
        String s5 = "a" + "b" + "c";
        String s6 = "abc";
        System.out.println(s5 == s6);//true
        System.out.println(s5.equals(s6));//true*/

        System.out.println("4==============");
        String s1 = "ab";
        String s2 = "abc";
        String s3 = s1 + "c";
        System.out.println(s3 == s2);//false
        System.out.println(s3.equals(s2));//true



    }
}
posted @ 2022-03-26 11:43  不只是智能hello  阅读(28)  评论(0)    收藏  举报