1.(单选题)What will be printed when you execute the following code? class C { C() { System.out.print("C"); } } class A { C c = new C(); A() { this("A"); System.out.print("A"); } A(String s) { System.out.print(s); } } class Test…
public class Test { public static void main(String[] args) { String str1="good"; System.out.println(str1=="good"); System.out.println(str1.equals("good")); //============================== String str2="goodjob"; Sys…
java String 是不可改变的类型. String a = "hello2"; String d = "hello"; final String b = "hello"; String c = b + "2";// final相当于常量,编译阶段直接加入常量池 String cc = “hello”+“2”: 类似于 final修饰的,在编译期间,会自动优化处理为:hello2 并加入常量池,所以和a比较相等,和e比较不…
1 == 返回值是true/false; (1) 基本数据类型比较的就是值(2)引用型数据类型就是地址值 public class Test1 { public static void main(String[] args) { int i = 1; int j = 1; System.out.println(i == j); Test1 t1 = new Test1(); Test1 t2 = new Test1(); System.out.println(t1); System.out.p…
==比较的是对象的地址,也就是是否是同一个对象: equal比较的是对象的值. Integer r1 = new Integer(900);//定义r1整型对象Integer r2 = new Integer(900);//定义r2整型对象System.out.println(r1==r2);//返回falseSystem.out.println(r1.equal(r2));//返回true =============equal是用来判断一个字符串的,比如:String s = test;if…