Java setters and getters

后端 未结 7 1639
情书的邮戳
情书的邮戳 2020-12-06 22:42

I have been struggling with setters and getters in java for quite a long time now.

For instance, if I want to write a class with some information as name, sex, age

7条回答
  •  太阳男子
    2020-12-06 23:27

    You create an object by instantiating the constructor as follows

    Personinfo pi = new Personinfo("Anna", "female", "17");
    

    You can then call methods upon that object as follows

    pi.setName("Alan");
    

    or

    pi.getName();
    

提交回复
热议问题