Forums Register Login

Review Questions #6 in chapter 4, on page 219 (Java OCA 8 Programmer I Study Guide)

+Pie Number of slices to send: Send
I can't understand this question.



I chose option B, because I understand such as "is not visible" belong to private fields and package private methods. Then I saw correct answer I thought that I understand wrong, "is not visible" belong to public class, not private fields and package private methods. The correct answer is D, but I can't understand it. I read that we can use access modifiers for all methods and instance variables. Maybe my english is not enough for understanding option D. Please explain it. Thanks in advance
1
+Pie Number of slices to send: Send
Let us walk through every possible answer. First the wrong ones:
A. private (most restrictive) < default / package-private < protected < public (least restrictive)
B. if the class is public, the class is visible to any class (in or outside the package) (the access level of fields and methods is not relevant to determine if the class itself is visible)
C. Such access modifier doesn't exist (you only have 3 access modifiers and 4 access levels). So any package-private class is visible to any class in that package, no possibility to restrict this
E. That's complete nonsense: there is no access modifier which restricts access based on the name of a class, method or variable

Now the correct one. Answer D is nothing more than thisI used access modifiers to allow access to all methods (using the public access modifier) and using the private access modifier I made sure you can't access any instance variable.

Hope it helps!
Kind regards,
Roel

+Pie Number of slices to send: Send
 

Roel De Nijs wrote: Now the correct one. Answer D is nothing more than this
I used access modifiers to allow access to all methods (using the public access modifier) and using the private access modifier I made sure you can't access any instance variable.



After your example everthing is clear, Roel. Thanks
Dinner will be steamed monkey heads with a side of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1160 times.
Similar Threads
OCA Java SE 8 - a few basic queries
wrong answer for review question (Java OCA 8 Programmer I Study Guide)
OCA Exam gotchas!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:36:03.