© Doug Winnie 2021
D. WinnieEssential Java for AP CompScihttps://doi.org/10.1007/978-1-4842-6183-5_57

57. Access Denied: Protected and Private

Doug Winnie1  
(1)
Mission Hills, KS, USA
 

When we create classes, we are creating a blueprint for how each instance will operate and the data that it will contain. It also defines the rules for how a programmer can access that data and provide protections for the fields that are inside of it.

Before we dive into the code, let’s refer back to our role-playing game example. When a player achieves certain activities like defeating enemies, completing quests, or attaining key items, they gain experience points, or XP. These points define what level your character is, and with each new level you attain, you can do ...

Get Essential Java for AP CompSci: From Programming to Computer Science 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.