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,這個敘述應該是多型的概念。