本身最近在面試的時候,遇到兩個面試題記憶比較深入,這裏記下來分享給你們.
1. 以下給出了兩個Java類
父類(Parent)
public class Parent {
static{
System.out.println("Parent_1");
}
{
System.out.println("Parent_2");
}
public Parent(){
System.out.println("Parent_3");
}
}
子類 (Child)
public class Child extends Parent {
static{
System.out.println("Child_1");
}
{
System.out.println("Child_2");
}
public Child(){
super();
System.out.println("Child_3");
}
public static void main(String args[]){
new Child();
}
}
請寫出正確的打印順序.
2. 給出以下的Java代碼(這道題頗有意思喲!)
public class Test {
public static void main(String[] args){
Integer m1 = 25;
Integer m2 = 25;
Integer n1 = new Integer(25);
Integer n2 = new Integer(25);
Integer x1 = 127;
Integer x2 = 127;
Integer y1 = 128;
Integer y2 = 128;
System.out.println(m1==m2);
System.out.println(n1==n2);
System.out.println(x1==x2);
System.out.println(y1==y2);
}
}
請寫出最後的輸出結果.