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.


How is 'friendly access' achieved?

  1. Using the friend keyword

  2. Using no access specifier

  3. Making members public

  4. Making members protected

The correct answer is: Using no access specifier

Friendly access is achieved by using the 'friend' keyword and providing that keyword in front of the specific function or class that you want to give access to. Option A is incorrect because using the keyword itself does not automatically grant access - it must be followed by a specific function or class. Option C is incorrect because making members public makes them accessible to anyone, not just friends. Option D is incorrect because making members protected allows access only to derived classes, not friends.