public class Person
{
public String name;
public String telephoneNumber;
public void print()
{
System.out.println(name + " " + telephoneNumber);
}
}
然后,在主类中,我可以编写以下代码:
class testPerson
{
public static void main(String[] args)
{
Person test;
test = new Person();
test.name = "Mary";
test.telephoneNumber = "01234 567890";
test.print();
}
}
You take out the money from your purse and hand it over to the delivery boy. (You are in control of hiding the internal details (drivers license etc.)) Alternatively,
你可以将钱包交给送货员并要求他从中取出钱。通过这样做,您将不再受控制。你正在暴露内部细节。
阅读信息隐藏 http://en.wikipedia.org/wiki/Information_hiding and 封装不是信息隐藏 http://www.javaworld.com/jw-05-2001/jw-0518-encapsulation.html.