java面试问题分享

java面试问题分享

**

朋友分享给我的面试题 感觉很有意思

**

public class A {
	public void people(){
		System.out.println("a1");
		
	}
	{
		System.out.println("a2");
	}
	static {
		System.out.println("a3");
	}
}
public class B extends A{
	public void people1(){
	System.out.println("b1");
		
	}
	{
		System.out.println("b2");
	}
	static {
		System.out.println("b3");
	}

}
public class C {
	public static void main(String[] args) {
		

		B b = new B();
	
	}

}

猜一下结果如何?

a3
b3
a2
b2

想得到吗?

public class C {
	public static void main(String[] args) {
		
		B b = new B();
		b.people();
		b.people1();
	
	}

}

这样呢?再来猜一下

a3
b3
a2
b2
a1
b1

如果是这样的呢

public class C {
	public static void main(String[] args) {
		
		B b = new B();
		b.people1();
		b.people();
		
	
	}

}

结果却是这样的

a3
b3
a2
b2
b1
a1

猜你喜欢

转载自blog.csdn.net/Riding_ants/article/details/106584151