Accessor Methods in Java

后端 未结 8 1402
野趣味
野趣味 2021-01-03 06:44

So I have a question on \"setter\" and \"getter\" methods and how useful they are or aren\'t.

Let\'s say I just write a very basic program like the following:

<
8条回答
  •  [愿得一人]
    2021-01-03 07:36

    You can always develop an application without using getter and setter methods.As you have explained.But using getter and setter is better practice because access modifiers private/public gives you encapsulation which is OOPS feature. You can always write your program without using OOPS features like encapsulation,abstraction,inheritance...but if you write large applications without using you will have trouble in maintaining and would soon realize the importance of these features.

提交回复
热议问题