Can parent and child class in Java have same instance variable?

后端 未结 4 1368
说谎
说谎 2020-12-15 21:43

Consider these classes:

class Parent {
 int a;
}

class Child extends Parent {
 int a; // error?
}

Should the declaration of a

4条回答
  •  心在旅途
    2020-12-15 22:03

    Its a little bit like marrying your cousin; Legal, but not advised.

    It can lead to all kinds of confusing behaviour, as the subclass declaration hides the parent class declaration.

提交回复
热议问题