Somewhere I have read import java.*; This example will compile, and it will try to import any classes within the directory java. It will not, however, import any of the packages located in subdirectories of java. In the preceding instance, there are no classes located directly in the Java package, therefore nothing will be imported.
But in the above coding,it did show compile error as stated
And consider the below program that worked successfully without any error.
And another class in different package
What is the rule behind using import java.* (or) import payroll.*; .Please help me.
posted 9 years ago
Note that the first code does not compile exactly for the reason you mentioned.
does not import subpackages.
You cannot use the Date class because you did not import the package it is in.
The other code compiles because the class you created is part of the payroll package and you import it.