Getters/setters in Java

后端 未结 7 1843
轻奢々
轻奢々 2021-02-18 13:18

I\'m new to Java, but have some OOP experience with ActionScript 3, so I\'m trying to migrate relying on stuff I know.

In ActionScript 3 you can create getters and sette

7条回答
  •  醉梦人生
    2021-02-18 14:04

    In Java, the only option you have without exposing the internals of your object is to make your own getters and setters as you have in your example.

    The convention is to prepend get or set in front of the field which is being altered. So, as in your example, the field name would have getName and setName methods as their corresponding getter and setter, respectively.

提交回复
热议问题