Protecting Our Data QuizS2C Home « Protecting Our Data Quiz

OO Concepts Quiz 2

The quiz below tests your knowledge of the material learnt in OO Concepts - Lesson 2 - Encapsulation - Protecting Our Data.

Question 1 : What mechanism is used for encapsulation in Java?
- We use <i>access modifiers</i> as our mechanism for encapsulation in Java.
Question 2 : Getter methods should not be passed an argument?
- Getter methods should NOT be passed an argument.
Question 3 : What are commonly known as getters and setters?
- Accessors and mutators are commonly known as getters and setters.
Question 4 : Setter methods should return a type?
- Getter methods should NOT return a type.
Question 5 : Which access modifier should we use with our instance variables?
- We should use the <code>private</code> <i>access modifier</i> with our instance variables.
Question 6 : Does the following code conform to the JavaBean standard for getting the value of an instance variable called bootWidth?

public int getbootWidth() {
    return bootWidth;
}
- The name of the method should be <code>getBootWidth()</code> to conform, the rest is fine.
Question 7 : How many arguments should we pass to our setters?
- We should only ever pass 1 argument to our setters.
Question 8 : Does the following code conform to the JavaBean standard for setting the value of an instance variable called bootWidth?

public void setBootWidth(int width) {
    this.width = width;
}
- This setter methods conforms to the <i>JavaBean</i> standard for setting the value of an instance variable called <code>bootWidth</code>.
Quiz Progress Bar Please select an answer


What's Next?

In the next quiz we test your knowledge of inheritance basics.