多态 upcast downcast

eg1:

public class Cat {
       protected static String color="random";
       
       public void showColor()
       {
        System.out.println("color:"+color);
       }
       public static void showCatColor()
       {
        System.out.println("color2:"+color);
       }
}


public class WhiteCat extends Cat
{
  protected static String color="white";
     
  public WhiteCat()
  {
   super();
  }
     public void showColor()
     {
      System.out.println("catColor:"+color);
     }
     public static void showCatColor()
     {
      System.out.println("catColor2:"+color);
     }

}

 

输出结果:

 

catColor:white
color2:random
catColor:white
catColor2:white

 注意到:static方法是不会被继承的好像。

 

refurl:1、http://zhidao.baidu.com/question/59143960

2、http://blog.csdn.net/zhu_apollo/article/details/1903374

你可能感兴趣的:(cast)