java例程练习(super关键字)

public class Test {
	public static void main(String[] args) {
		ChildClass cc = new ChildClass();
		cc.f();
	}
}

class FatherClass {
	public int value;
	public void f() {
		value = 100;
		System.out.println("FatherClass.value = " + value);
	}
}

class ChildClass extends FatherClass {
	public int value;
	public void f() {
		super.f();
		value = 200;
		System.out.println("ChildClass.value = " + value);
		System.out.println(value);
		System.out.println(super.value);
	}
	
}


输出结果:

FatherClass.value = 100
ChildClass.value = 200
200
100

你可能感兴趣的:(java例程练习(super关键字))