Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


Which of the following is NOT a way to grant access to a class member?

  1. Making the member public

  2. Using the default package access

  3. Declaring the class member as static

  4. Providing accessor/mutator methods

The correct answer is: Declaring the class member as static

One way to grant access to a class member is by making it public, meaning other classes and methods can access it. B is incorrect because using the default package access can grant access to a class member within the same package. D is incorrect because providing accessor/mutator methods allows other classes to modify or retrieve the value of a private class member. C is incorrect because declaring a class member as static has no impact on granting access to it. Static simply means the member belongs to the class rather than to an instance of the class.