题目1
class X { Y b = new Y(); X() { System.out.print("X"); } } class Y { Y() { System.out.print("Y"); } } public class UserDao extends X{ Y y = new Y(); UserDao(){ System.out.print("Z"); } public static void main(String[] args) { new UserDao(); } }
先初始化父类数据,在初始化子类数据。结果 YXYZ
题目2
public class DemoTest { public static void main(String[] args) { A a = new A(); a.b(); a.b(); } } class A{ private int b; void b(){ final int a=b; b = 1; System.out.println(a); } }