Encapsulation - Access Modifiers QuizS2C Home « Encapsulation - Access Modifiers Quiz

OO Concepts Quiz 1

The quiz below tests your knowledge of the material learnt in OO Concepts - Lesson 1 - Encapsulation - Access Modifiers.

Question 1 : Which access modifiers can we explicitly apply to our top-level classes?
- We can only explicitly apply the <code>public</code> <i>access modifiers</i> to our top-level classes.
Question 2 : If no access modifier is used on a member the default is public?
- If no <i>access modifier</i> is used on a member the default is no modifier, commonly known as package-private which means it is only accessible within its own package.
Question 3 : Which access modifiers can we explicitly apply to our members?
- We can explicitly apply the <code>private</code>, <code>protected</code> or <code>public</code> <i>access modifiers</i> to our members.
Question 4 : We can apply an access access modifier to a constructor?
- We CAN apply an <i>access modifier</i> to a constructor.
Question 5 : Which access modifier limits member visibility to the class it resides in?
- The <code>private</code> <i>access modifier</i> limits member visibility to the class it resides in.
Question 6 : We use the private access modifier on a top-level class to stop subclassing?
- We can only explicitly apply the <code>public</code> <i>access modifier</i> to our top-level classes, we would use the <code>final</code> <i>field modifer</i> to stop <i>subclassing</i>.
Question 7 : How do we gain access to the private instance variables of a class?
- We gain access to the <code>private</code> instance variables of a class using <code>public</code> methods of the called class.
Question 8 : Not using an access modifier on a member means it is only available from within the same package?
- Not using an <i>access modifier</i> on a member DOES mean it is only available from within the same package.
Question 9 : Which access modifier is used to allow access to allow access from a sub-package?
- The <code>protected</code> <i>access modifier</i> is used to allow access from a sub-package.
Quiz Progress Bar Please select an answer


What's Next?

In the next quiz we test your knowledge further on encapsulation when we look at protecting our data.