Andreas Svenkson wrote:
As you can see, Iface is not in a specific package, and the source is placed in the root of the classpath. So, how does one correctly reference the interface Iface, from within class User? Is it even possible when the interface does not belong to a named package?
// Andreas
Ikpefua wrote:
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Prepare for 'OCA Java SE 8 certification' with eJavaGuru.com
Author of Manning's OCA Java SE 8 bookProgrammer I Certification Guide, OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
Mala Gupta wrote:Most of the books claim that all non packaged classes and interfaces are defined in a 'default' package, which is imported in all classes and interfaces, automatically by Java.
Stephan van Hulst wrote:
Mala Gupta wrote:Most of the books claim that all non packaged classes and interfaces are defined in a 'default' package, which is imported in all classes and interfaces, automatically by Java.
I think you either misread, or those books are wrong. The default package is never imported automatically, and there is also no way to import it manually.
Ikpefua wrote:
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
7.4.2 Unnamed Packages
A compilation unit that has no package declaration is part of an unnamed package.
Note that an unnamed package cannot have subpackages, since the syntax of a package declaration always includes a reference to a named top level package.
As an example, the compilation unit:
class FirstCall {
public static void main(String[] args) {
System.out.println("Mr. Watson, come here. "
+ "I want you.");
}
}
defines a very simple compilation unit as part of an unnamed package.
An implementation of the Java platform must support at least one unnamed package; it may support more than one unnamed package but is not required to do so. Which compilation units are in each unnamed package is determined by the host system.
In implementations of the Java platform that use a hierarchical file system for storing packages, one typical strategy is to associate an unnamed package with each directory; only one unnamed package is observable at a time, namely the one that is associated with the "current working directory." The precise meaning of "current working directory" depends on the host system.
Unnamed packages are provided by the Java platform principally for convenience when developing small or temporary applications or when just beginning development.
Prepare for 'OCA Java SE 8 certification' with eJavaGuru.com
Author of Manning's OCA Java SE 8 bookProgrammer I Certification Guide, OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
Seetharaman Venkatasamy wrote:Stephan is correct. you cant mix non-packaged class and packaged class. if you do , you will get compilation error!
Don't get me started about those stupid light bulbs. |