the use of private keyword

后端 未结 12 1771
栀梦
栀梦 2021-01-01 14:00

I am new to programming. I am learning Java now, there is something I am not really sure, that the use of private. Why programmer set the variable as private then write , ge

12条回答
  •  悲哀的现实
    2021-01-01 14:54

    I highly recommend the book Effective Java, it contains a lot of useful information about how to write better programs in Java.

    Your question is addressed in items 13 and 14 of that book:

    • Item 13: Minimize the accessibility of classes and members
    • Item 14: In public classes, use accessor methods, not public fields

提交回复
热议问题