Question OOP-ENC-0006
EasyIn Java, who can access a protected member?
- A.
Only the class itself
- B.
Everyone
- C.
Show answer and explanation
Answer: D
protected is wider than package-private: subclasses in other packages can also access it.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Encapsulation question
In Java, who can access a protected member?
Only the class itself
Everyone
Answer: D
protected is wider than package-private: subclasses in other packages can also access it.
Only classes in other packages
The class itself, its subclasses and classes in the same package