因为你把一个B1的实例赋给了一个A类的对象b,所以,b是B1的对象,也是A的对象

解决方案 »

  1.   

    (firstly, I am sorry for type English coz my OS is only English-supported)Look at this:class A{
      //get rid of the modifier "static"
      void func1(){
        System.out.println("super func1 static");
      }
    }public class B1 extends A{
      //get rid of the modifier "static"
      void func1(){
        System.out.println("this func1 static");
      }  public static void main(String[] args){
        A b = new B1();
        b.func1();
        if(b instanceof B1)
          System.out.println("b is B1's object");
        if(b instanceof A)
          System.out.println("b is A's object");
      }
    }and the output is below:
    this func1 static
    b is B1's object
    b is A's objectSo, we could draw a conclusion:
      Because the method "func1" in origin source is a static method, so when b was declared as class A, the method is refer to class A's func1. You could image that :
      A b = new B1();
        is same as
      A b = null;  // at here, static method func1 is refer to A's.
      b = new B1();// at here, this static method couldn't be changed.With all words; static method has nothing to do with instance. It only depend on the class you derived but not the sub-clause after "new" keyword.To additional: because b is a instance of class B1, and B1 is derived from A. So instanceof will always return ture in spite of compare it to A or B1.Are you clear?
      

  2.   

    出现"使用或覆盖一个不鼓励使用的API"提示时,是怎么回事?