Why doesn’t Java allow private members in interface?

By | July 19, 2019

Question

Why doesn’t Java allow private members in interface? Is there any particular reason?

Solution

From the Java Language Spec, (Access Control):

“The Java programming language provides mechanisms for access control,
to prevent the users of a package or class from depending on
unnecessary details of the implementation of that package or class.”

Access control is all about hiding implementation details. An interface has no implementation to hide.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *