那GET又有什么意义?



所有跟贴·加跟贴·新语丝读书论坛http://www.xys.org/cgi-bin/mainpage.pl

送交者: HunHunSheng 于 2005-1-29, 18:51:34:

回答: 保护私有,使我们的发展建设更加健康 由 bluesea 于 2005-1-29, 18:28:29:

If diameter is a private variable of class Cicrle
x=Cirlce.getDiameter();

int getDiameter()
{
return diameter;
}

You can make diameter a public variable

and x=Circle.diameter


Of course, you can also add xssoem thing more
But yiou can make the variable public and still ukepp these method

At least oen yiou have Get amd Set method, the purpose
of making them private (i.e. encapsulation) is beaten.






所有跟贴:


加跟贴

笔名: 密码(可选项): 注册笔名请按这里

标题:

内容(可选项):

URL(可选项):
URL标题(可选项):
图像(可选项):


所有跟贴·加跟贴·新语丝读书论坛http://www.xys.org/cgi-bin/mainpage.pl