为啥不能调用父类变量?
父类Animal
package com.imooc; public class Animal { //父类中的成员变量 public String name; public int age; private int weight; public void eat() { System.out.println("吃东西"); } }
子类Dog
package com.imooc; public class Dog extends Animal { }
测试类Initial
package com.imooc; public class Initial { Dog dog = new Dog(); dog.age = 2; dog.name = "xiaotian"; }
在测试类调用父类成员变量时报错
dog.age = 2;
dog.name = "xiaotian";
以上两句报错
错误红线在age和name下