10.05

类的继承

  1. public class Apple extends Fruit
  2.  {
  3.  public static void main(String[] args)
  4.  {
  5.  //创建Apple对象
  6.  Apple a = new Apple();
  7.  //Apple 对象本身没有 weight 成员变量
  8.  //因为Apple 父类有 weight 成员变量, 所以也可以访问 Apple 对象的 weight 成员变量.
  9.  a.weight = 56; 
  10. //调用 Apple 对象的 info() 方法 
  11. a.info()
     }
  12.  
    }
posted @ 2020-10-05 14:47  王昊宁  阅读(90)  评论(0编辑  收藏  举报