protected data in abstract class

前端 未结 8 1762
闹比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:45

    If someone subclasses your class, and puts the subclass in the same package as your current class, they may want to override your getters and setters. For example, they wantto make sure that i may only be set to a value greater than 1.

    Other than that, it's really up to you. The convention is that there are getters and setters for everything though.

提交回复
热议问题