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"

      }

    }

  • 相关阅读:
    verilog RTL编程实践之四
    TB平台搭建之二
    hdu3466 Proud Merchants
    poj2411 Mondriaan's Dream (用1*2的矩形铺)
    zoj3471 Most Powerful
    poj2923 Relocation
    hdu3001 Travelling
    poj3311 Hie with the Pie
    poj1185 炮兵阵地
    poj3254 Corn Fields
  • 原文地址:https://www.cnblogs.com/children/p/2711614.html
Copyright © 2011-2022 走看看