继续转载当年的坑系列,这个系列的题目都是当年从各种坑中收集而来的。
本题中只要有跟final字符串有关的操作,最后结果都相等

false

true

true

true

true


                String ab = "ab";
			
	        String a = "a";
	        String b = a +"b";
	        System.out.println(b == ab);
	        
	        final String s12 = "a";
	        String s22 = s12 +"b";
	        System.out.println(s22 == ab);
	        
	        final String s1 = "ab";
	        String s4 = "abcdef";
	        String s5 = s1 + "cdef";
	        String s6 = "ab" + "cdef";
	        System.out.println(s4 == s5);
	        System.out.println(s4 == s6);
	        System.out.println(s5 == s6);

继续转载当年的坑系列,这个系列的题目都是当年从各种坑中收集而来的。

 


	public class Test23 {
		static {
			name = "B";
		}
		static String name = "A";
		static {
			System.out.println(name);
		}
	
		public Test23() {
			System.out.println("初始化" + name);
		}
	
		public static void main(String[] args) {
	
		}
	}

会输出什么?
答案:
Continue reading

继续转载当年的坑系列,这个系列的题目都是当年从各种坑中收集而来的。

 

 

public class 初始化重载 {
    public static void main(String[] args) {
        new Derived();
    }
}
 
class Base {
    private int i = 2;
     
    public Base() {
        display();
    }
    public void display() {
        System.out.println(i);
    }
}
 
class Derived extends Base {
    private int i = 22;
     
    public Derived() {
        i = 222;
    }
     
    public void display() {
        System.out.println(i);
    }
}

问:会输出什么?
答案:
Continue reading