To promote encapsulation, Java provides an access modifier of ________ type.
-
public
-
private
-
protected
-
none of these
B
Correct answer
Explanation
It is an access modifier: private means that only code within same class can access the private data members.To encapsulate the data or hide the data we use private instance variable and provide public getter and setter methods. For example: class dog { private int size; public int getSize(){ return size;} public void set Size(int s ){size =s; }}, mark the instance variable(size) private and make the getter(getSize()) and setter(setSize()) methods public.