zoukankan      html  css  js  c++  java
  • java多态说明

    多态值得注意的地方:成员变量,和静态方法是不存在多态的概念的

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package com.fengli;

    /**
    *
    * @author Administrator
    */
    public class BaseClass {

    public int a =0;

    public static void printString(){
    System.out.println("base staitc String");
    }

    public void unStaticPrintString(){
    System.out.println("base unStaitc String");
    }

    }

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package com.fengli;

    /**
    *
    * @author Administrator
    */
    public class SubClass extends BaseClass{

    public int a =1;

    public static void printString(){
    System.out.println("staitc String");
    }

    @Override
    public void unStaticPrintString(){
    System.out.println("unStaitc String");
    }

    public static void main(String[] args){
    BaseClass bc = new SubClass();
    System.out.println(bc.a); //输出父类的值0
    bc.printString(); //打印父类的printString base staitc String
    bc.unStaticPrintString(); //打印子类的覆盖方法 unStaitc String
    }

    }

  • 相关阅读:
    构造函数与其他方法的区别
    记录点复习题目和linux学习
    找点面试题目
    linux代码常用查询!!!!!!!!!!!!
    python复习
    明天面试今天赶紧准备下
    文都计算机考研课程
    是时候刷笔试题目了
    倒排索引
    总结算法课程
  • 原文地址:https://www.cnblogs.com/working/p/5645979.html
Copyright © 2011-2022 走看看