Have a Question ?

Home / Answered Questions / CSE205 / cse205-quiz-4-encapsulation-q-344

(Solved): CSE205 Quiz 4 - Encapsulation  ...


CSE205

Quiz 4 - Encapsulation  

 Question 1

1 / 1 pts

Which is the best/most complete definition of encapsulation?

  •   Encapsulation is used to control how one may access and interact with an object of a class.  Data and internal helper methods are hidden in the back-end of the class, and a public interface is developed to provide controlled access and functionality.
  •   Encapsulation is the process of developing the properties and methods of a class. 
  •   Encapsulation is used to control how one may access and interact with an object of a class.  Data is accessed through getters and setters.
  •   It describes the idea of bundling data and methods that work on that data within a class.

Question 2

1 / 1 pts

Determine the best description of the qualities of getters & setters:orrect!

  •   They allow us to "black-box" access to properties in an object.  Users don't need to know how the data is being stored, they just need a public interface to work with relevant data.  This mentality can also control read & write access and allow us an opportunity to defend against invalid data.
  •   They allow us to indirectly access properties in an object
  •   They allow us to control how properties are stored in a class and who can read and write the data.
  •   Getters and Setters provide read-only or write-only or read/write access to the data stored in the class.  While they are short and seem trivial this is actually a very powerful tool at our disposal.  Direct access to properties invites all sorts of issues and side-effect, similar to using global variables.  Our data is less secure when we don't use getters and setters.

Question 3

1 / 1 pts

T/F? - Proper use of Encapsulation helps enhance our data security.rrect!

  •   True
  •   False 

 Question 4

1 / 1 pts

How do we achieve Encapsulation?orrect!

  •   Proper use of Access/Visibility Modifiers 
  •   Using only private properties
  •   Use of the abstract keyword
  •   Through the use of inheritence

Question 5

1 / 1 pts

At face value this class seems ok ... but really it's not... select all that are true

public class Student

{

        private PersonalInfo information;

       

        public PersonalInfo getInfo()

        {

                 return this.information;

        }

}

  •   We should decompose PersonalInfo and store the contents directly into student.  There's no point in having a "has a" relationshiporrect!
  •   Returning the PersonalInfo reference can open this Student to direct manipulation of their data. A more robust public interface should be created to protect and control access to PersonalInfo information.
  •   This is just a standard getter ... nothing wrong with that.
  •   This is technically encapsulated properly, but could have very negative consequences.

 Question 6

1 / 1 pts

Tell me about this code...

public class Test

{

        private int positiveNum;

       

        public void SetNumber(int value)

        {

                 if(value >= 0)

                         this.positiveNum = value;

                 else

                         throw new IllegalArgumentException("Value can't be negative!");

        }

}

Correct!

  •   This code maintains encapsulation
  •   This code breaks encapsulation 
  •   code is vulnerable 
  •   This code does not work/would not compile

Question 7

1 / 1 pts

Match the visibility modifiers to their best description

Correct!

private

             

Correct!

protected

             

Correct!

public

             

Correct!

default (Java)

             

 



We have an Answer from Expert View Expert Answer

Expert Answer


We have an Answer from Expert
Buy This Answer $15

-- OR --

Subscribe To View Unlimited Answers
Subscribe $20 / Month