- package ls.test;
- class Fu {
- int x = 4;
-
- Fu() {
- System.out.println("A fu() : " + getNum());
- }
- int getNum() {
- System.out.println("B fu getnum run...." + x);
- return 100;
- }
- }
- class Zi extends Fu {
- int x = 5;
- Zi() {
- System.out.println("C zi() : "+getNum());
- }
- int getNum() {
- System.out.println("D zi getnum run...." + x);
- return 200;
- }
- }
- class DuoTaiTest3 {
- public static void main(String[] args)
- {
- Zi f = new Zi();
- }
- }
复制代码 执行结果:
D zi getnum run....0
A fu() : 200
D zi getnum run....5
C zi() : 200
为什么第一句打印的是“D zi getnum run....0”
|