送交者: 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.