zoukankan      html  css  js  c++  java
  • JAVA 多态

    多态是编程语言给不同的底层数据类型做相同的接口展示的一种能力。一个多态类型上的操作可以应用到其他类型的值上面

    package peoplePack;
    
    public class JavaApp {
        public static void main(String[] args) {
            Young y = new Young();
            y.testInstanceMethod();
            
            People p = new Young();
            p.testInstanceMethod();
            
            People.testClassMethod();
            Young.testClassMethod();
        }
    }
    
    class People {
        public static void testClassMethod(){
            System.out.println("Static Method in People");
        }
        
        public void testInstanceMethod(){
            System.out.println("Instance Method in People");
        }
    }
    
    class Young extends People{
        public static void testClassMethod(){
            System.out.println("The static method in Young");
        }
        
        public void testInstanceMethod(){
            System.out.println("The instance method in Young");
        }
    }

    Output:

    The instance method in Young
    The instance method in Young
    Static Method in People
    The static method in Young

    Reference

    http://docs.oracle.com/javase/tutorial/java/IandI/override.html

  • 相关阅读:
    Nginx配置文件详解
    Mycat概述
    日志切割之Logrotate
    js数组(二)
    js数组(一)
    sass颜色
    scss
    HTML5新属性
    HTML5新元素
    Bootstrap
  • 原文地址:https://www.cnblogs.com/liangnote/p/4294801.html
Copyright © 2011-2022 走看看