爪哇塞特&吸气方法 [英] Java Setter & getter method

查看:78
本文介绍了爪哇塞特&吸气方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Plz给出了一些简单的setter和getter方法示例.请解释这些setter和getter方法的工作原理?

Plz give some simple example of setter & getter method. Explain how these setter & getter mthod works?

推荐答案

您的问题到底是什么? :confused:
getter只是类上的一种方法,用于检索类的私有成员的值(而setter用于设置其值).

例如:
What''s your problem exactly ? :confused:
A getter is simply a method on a class to retrieve the value of a private member of the class (and a setter is used to set its value).

For instance:
class MyClass {
   private int myVariable;

   public int getVariable() { return myVariable; }
   public void setVariable(int value)  { myVariable = value; } 
}


这篇关于爪哇塞特&吸气方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆