玩这是一类Encapsulate
具有公共财产和公共方法。确实访问修饰符有任何作用,在封装
class Encapsulate
{
public int a;
public int b;
public static void main(String...s)
{
Encapsulate e = new Encapsulate();
e.setVar(10,20);
System.out.println(e.getSome());
}
public void setVar(int a, int b)
{
this.a = a;
this.b = b;
}
public int getSome()
{
return a + b;
}
}
OOP概念Encapsulation
跟在这里?
我相信,因为二者都是在一个类粘合在一起是适用的,可能是我们可以称之为弱封装但封装。
但我不知道如何来证明这一点,因为我的搜索表明,类属性应该是私有的。
更新:在默认访问说明符的情况下什么。
引用来访问属性我不知道,如果真的是正确的,但通常我说*数据隐藏*和*封装*是相关的,但不相同。 – meskobalazs
这可能很有趣:http://programmers.stackexchange.com/questions/173547/what-is-the-difference-between-data-hiding-and-encapsulation – meskobalazs
如果我是绑定属性和方法使用公共访问说明符,比其他类隐藏起来并且结合在一起(这就是封装),除了其他类实例化或扩展它们。 –