zoukankan      html  css  js  c++  java
  • 父类 子类 调用 考点

    1、实例的属性的值取父类还是子类并不取决于创建对象的类型,而是取决于变量定义的类型。

    例:

    public class Father{

      public String value="Father";

    }

    public class Son extends Father{

      public String value="Son ";

      public static void main(String args[]){

        Father f=new Son();

        System.out.println(f.value);//输出"Father"

      }

    }

    2、在成员函数中访问成员变量时,成员变量的值取父类还是子类取决于是调用父类还是子类的成员函数。

    public class Father{

      public String value="Father";

      public String getValule(){

        return this.value;

      }

      public String getValule2(){

        return this.value;

      }

    }

    public class Son extends Father{

      public String value="Son ";

      public String getValule2(){

        return this.value;

      }

      public static void main(String args[]){

        Son s=new Son();

        System.out.println(s.value);//输出"Son"

        System.out.println(s.getValue());//输出"Father"

        System.out.println(s.getValue2());//输出"Son"

      }

    }

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