Java Reference
In-Depth Information
If you want to use a class named Person from com.jdojo.common package in the source code, you need to include
one of the following two import declarations in your source code:
import com.jdojo.common.Person;
or
import com.jdojo.common.*;
The following import declarations do not include classes in the package com or com.jdojo :
import com.jdojo.intro.Account;
import com.jdojo.intro.*;
You might think that an import declaration like
import com.*.*;
would let you use the simple names of all classes whose first part of package declaration is com. Java does not
support this type of wildcard use in an import declaration. You are allowed only to name one class in a package
( com.jdojo.intro.Account ) or all classes in a package ( com.jdojo.intro .*); any other syntax to import classes is
invalid.
The third part in a Java source code contains type declarations, which may contain zero or more declarations
for class, interface, and/or enum . According to the Java Language Specification, type declaration is also optional.
However, if you omit this part, your Java program does not do anything. To make your Java program meaningful, you
must include at least one class, interface, or enum declaration in your Java source code. I will defer the discussion of
interface and enum until later chapters in this topic. Let's discuss how to declare a class in a Java source code.
Class Declaration
In the simplest form, a class declaration looks like
class Welcome {
// Code for the class body goes here
};
Figure 2-3 shows parts of the above class declaration.
 
Search WWH ::




Custom Search