>

Java: `protected` vs `package-private`

TL;DR - The protected access modifier provides a level of access that is broader than package-private (i.e. Java default access modifier) but more restricted than public. protected: accessible from classes within the same package and subclasses (i.e. inherited) package-private: accessible from classes within the same package Example to illustrate protected access CodeCreator.java package com.example.cc; abstract class CodeCreator { // Protected abstract method protected abstract void createCode(); // Protected concrete method protected void startCreating() { System....

July 22, 2024 · 2 min · 400 words · Papattarada A. (Pun Pun)