protected data in abstract class

前端 未结 8 1761
闹比i
闹比i 2021-01-01 19:01

My question involves specifically Java, abstract classes, and the use of protected data. I am being told that all the data should be private, and protected getters/setters

8条回答
  •  孤城傲影
    2021-01-01 19:27

    If you don't need your child to directly access it, why would you let them ?

    It isn't a down side to use protected. But if it isn't necessary, maybe it's better to avoid it and control access on your fields.

提交回复
热议问题