Java OOP

 

SHORT ANSWER QUESTIONS

DATA ENCAPSULATION

 

QUESTIONS


Fill the blanks and short answer questions.  Solutions are at the bottom of this document.

 

 

a)    _____________ _____________ is the process of limiting access to instance variables to ensure data integrity.  This is done by making these variables private and providing limited access via instance methods.

b)    The keywords ___________ and ____________ are called access modifiers.  They dictate the locations from where variables and methods can be accessed.  There is also a protected access modifier that relates to inheritance as well as a default access modifier (no modifier) that can be used.

 

c)     We can make an instance variable ___________ to stop direct access to it from outside the class.  This could allow us to control what values it get.

 

d)    True or false.  A private instance variable is the same as a public instance variable from inside the class (so inside constructors and instance methods).  ____________

 

e)    For Point p, if we can access p.x, then we know that x is a ____________ instance variable.

 

f)      True or false.  Instance methods have access to the instance variables, even if they are private.  ___________

 

g)    A __________ ___________ is an instance method that returns the value of an instance variable.

h)    A __________ ___________ in an instance method that changes the value of an instance variable.

i)       A class that does not allow the user to change its instance variables once an object is created is said to be ________________.  An example of such a class is the String class.

j)       A class that allows the user to make changes to its instance variables is said to be _______________.

 

SOLUTIONS

 

Click here.