Java的继承和重写示例代码

观看代码并选择代码执行的结果:

Java的继承和重写示例代码

abstract class A {
	int a = 2;

	abstract void test();

	public void test2(int a) {
		this.a = a;
		out();
		te();
	}

	public static void out() {
		System.out.println("A.out()");
	}
	
	public void te() {
		System.out.println("A.te()");
	}
}

public class B extends A {
	int a = 5;

	@Override
	public void test() {
		a = super.a;
	}

	public static void main(String[] args) {
		B b = new B();
		
		b.test2(10);
		
		System.out.println(b.a);
		
		out();
	}

	public static void out() {
		System.out.println("B.out()");
	}
	
	public void te() {
		System.out.println("B.te()");
	}
}

 若将第30行的

B b = new B();
改为
A b = new B();
后又该选择哪一组答案呢?

你可能感兴趣的:(java,继承,属性,重写)