- class Fu
- {
- int x = 3;
- int y = 4;
- int set()
- {
- return x+y;
- }
- }
- class Zi extends Fu
- {
- int x;
- Zi(int x)
- {
- this.x = x;
- }
- }
- class Test1
- {
- public static void main(String[] args)
- {
- Zi z = new Zi(2);
- System.out.println(z.set());//为什么输出是父类的x和y的和7??
- Fu f = z;
- System.out.println(f.x);
- }
- }
复制代码
|
|