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

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

Master your knowledge of Java programming with our immersive quiz based on 'Thinking in Java'. Test your skills with detailed questions and receive hints and explanations to enhance your learning. Get ready to ace your Java 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.