A class design requires that a member variable cannot be accessible directly outside the class. Which modifier should be used to obtain the access control?()
- A public
- B no modifier
- C protected
- D private
A class design requires that a member variable cannot be accessible directly outside the class. Which modifier should be used to obtain the access control?()
这个在前面也有叙述,java有四种访问类型,分别为:public,protected,default,private,其中public变量可以被所有的外部类访问,而pretected的可以被同一个包及该类的子类访问,default即没有任何修饰符的变量可以被同一个包中的类访问,而private变量只能在被该类内部被访问。题目中的外部类应该理解为除该类自身的所有其它类,因此只有使用private可以达到要求