Java继承使用super()关键字访问父类成员

时间:2018-08-15 16:59:21

标签: inheritance polymorphism super

我需要帮助来理解为什么即使在类级别创建对象后也无法访问main方法内的父类成员

父班

     package SuperConcepts;

     public class SuperConceptsExample {

      public String color = "red";

       }

儿童班

package SuperConcepts;

public class SuperConceptsExample1 extends SuperConceptsExample {

String color1 = "orange";

SuperConceptsExample s1 = new SuperConceptsExample();

public void display() {

    System.out.println(super.color);

}

public static void main(String[] args) {

    System.out.println(s1.display);  // Unable to access it though i have created the object

}

}

0 个答案:

没有答案