In Java- “Static Members of the default package cannot be imported”- Can some one explain this statement? It would be better if its with an example. I am not sure if it has a really simple answer but then I tried to understand but couldn’t figure it out.
Share
It means that if a class is defined in the default package (meaning it doesn’t have any package definition), then you can’t import it’s static methods in another class. So the following code wouldn’t work:
The import fails because you can’t import static methods from a class that’s in the default package, which is the case for Example1. In fact, you can’t even use a non-static import.
This bug report has some discussion about why Java acts this way, and it was eventually closed as "not a defect" — it’s the way Java was designed to behave. Default package just has some unexpected behavior, and this is one of the reasons why programmers are encouraged to never used the default package.