Help to understand the issue with protected method

前端 未结 6 1163
野的像风
野的像风 2021-01-12 00:54

I\'m reading Sybex Complete Java 2 Certification Study Guide April 2005 (ISBN0782144195). This book is for java developers who wants to pass java certification.

6条回答
  •  离开以前
    2021-01-12 01:19

    Because variable type is irrelevant here till it is 'sane' in context of question. As method abby() belongs to X (and Y inherits it), it doesn't matter with what type variable referencing instance of Y is declared: it can be either X or Y. Be abby() accessible, we could call it through both variables:

    X myY1 = new Y();
    myY1.abby();
    
    Y myY2 = new Y();
    myY2.abby();
    

提交回复
热议问题