zoukankan      html  css  js  c++  java
  • 继承ExtendsOne

    package Test;
    /*
    * 注意:子类不能继承父类的私有成员(private),不能继承父类的构造器
    * 子类拥有父类的所有成员,除了私有和构造器
    * 若父类的方法被子类重写了,则调用子类方法
    *
    */

    public class ExtendsOne {

      public static void main(String[] args) {
        Apple a=new Apple();
        a.weight=10.21;
        a.info();//10.21
        a.fun();//子类方法重写了fun()
      }

    }
      class Fruit{
        public double weight;
        public void info() {
          System.out.println(weight);
        }
      public void fun()
      {
        System.out.println("父类方法fun()");
      }
    }
    class Apple extends Fruit{
      public void fun()
      {
        System.out.println("子类方法重写了fun()");
      }
    }

  • 相关阅读:
    UDP 远程主机强迫关闭了一个现有连接
    CSS float 理解
    C# 启用事务提交多条带参数的SQL语句
    EF学习之DBFirst
    说一说JavaScript 中的原型ProtoType
    Unity
    Unity
    Unity
    Unity
    Godot
  • 原文地址:https://www.cnblogs.com/zhujialei123/p/8966229.html
Copyright © 2011-2022 走看看