Using a private variable in a inherited class - Java

前端 未结 3 1480
暖寄归人
暖寄归人 2020-12-03 06:07

Need to have more understanding about the private variables and inheritance. Earlier my understanding was if there is field in a class and when I\'m inheriting the class, th

3条回答
  •  自闭症患者
    2020-12-03 06:27

    private variables / members are not inherited. That's the only answer.

    Providing public accessor methods is the way encapsulation works. You make your data private and provide methods to get or set their values, so that the access can be controlled.

提交回复
热议问题