举个例子:
java中所有的类 的超类都是Object
难道 new Object(); 的 引用能随便使用一个 子类的引用吗?
例如 : String str = new Object();  这肯定不对呀

解决方案 »

  1.   

    B which is subclass of class A often carries more features besides those extends from A, in other words,A is subset of B.
    = is an assignment symbol which requires the right side at least owns the whole features of the class on the left side.
    Therefore,A a = new B() is correct whereas B b = new A() will fail to pass the compilation.
    More vivid example, let us suppose that you need a book, your friend offer you a sheet of paper.Obviously your requirement cannot be catered,although a sheet of paper is a part of a book.But if your friend offer you a book and a sheet of paper.S/he can cater you. Perhaps it's not a suitable example, but it can make you easy to understand this question.
      

  2.   

    B a=B(new A())
    可以这么写 ,这样只能调用父类有的方法 ,子类中自己的方法是不能被调用的。