private

If we mark our method or variable as private, then we cannot access either of them outside the class. They cannot be accessed outside the package, or outside the same class. If we want to access this in our ArraysDemo example, we cannot do that. Even if we try to, it throws an error, as shown in the following screenshot:

Quick fixes drop down with a suggestion to correct the code error for private

This is so because, if we mark any method or variable as private, we cannot access it outside that particular class. Until and unless we change it to something else, it throws an error. This applies to the variable as well.

If you want a ...

Get Hands-On Automation Testing with Java for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.