Which statement best describes encapsulation?
A. Encapsulation ensures that classes can be designed so that only certain fields and methods of an object are accessible from other objects.
B. Encapsulation ensures that classes can be designed so that their methods are inheritable.
C. Encapsulation ensures that classes can be designed with some fields and methods declared as abstract.
D. Encapsulation ensures that classes can be designed so that if a method has an argument MyType x, any subclass of MyType can be passed to that method.
题解
选项 A,封装可以确保类别对象中,只有特定的字段和方法能被其他对象访问。
选项 B,封装的方法不一定需要被继承,封装和继承没有什么直接的关联性。
选项 C,字段不能是抽象的。
选项 D,这个叙述应该是多态的概念。
