- class Fu{
- int num = 4;
- Fu(){
- num = 5;
- }
- }
- class Zi extends Fu{
- int num = 6;
- public void method(){
- int num = 7;
- System.out.println(num);
- }
- }
- class demo{
- public static void main(String[] args) {
- Zi z = new Zi();
- z.method();
- }
- }
复制代码 运行结果一开始是 7;
想输出6的话 System.out.println(num); 改为 System.out.println(this.num);
想输出5的话 System.out.println(num); 改为 System.out.println(super.num);
那要是想输出 4 的话怎么改啊 ?? 求解
|