多态值得注意的地方:成员变量,和静态方法是不存在多态的概念的
/*
* 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
}
}