[java] Why can't I make my abstract class package-private or protected? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

[java] Why can't I make my abstract class package-private or protected?

My package structure looks like this: myFolder |_mySubFolder | |_mySubClass.java |_myAbstractClass.java Since the "mySubClass" is in the same folder as "myAbstractClass", I thought that "mySubClass" can have access to it if "myAbstractClass" has the visibility modifiers "package-private" or "protected"? But for some reasons it doesn't have.

6th May 2017, 4:02 PM
Thanh Le
Thanh Le - avatar
1 Answer
0
Actually, they don't belong to the same package. Whereas we recognize hieralchical package structures, Java compiler does not. "myFolder" and "myFolder.mySubFolder" just have different names so they should be treated as independent packages without any inclusive relationships.
6th May 2017, 6:25 PM
Twelfty
Twelfty - avatar