简体   繁体   中英

Is it a must to import a java class or package that is lower in the package hierarchy than the class trying to access it?

So I was working around with packages in java. And I made a subpackage and then tried to make an object from it in the main which was in the higher package in the hierarchy so it required me to use an import statement in order to use this class. Is there any way to be able to access the class in the subpackage without needing to import.

No.That's how packaging works in Java.

If you use a good IDE, you won't need to worry about imports.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM