Using Import Statements
We can use import function in the two ways :
- wildcard import
- explicit class import
Import statements are little more than a way for us to save keystrokes when we\'re typing our code. We essentially give the class a longer name, which we call the fully qualified name.
The compiler would never know what you meant if you typed the following:
class Bar {
void doStuff() {
Foo f = new Foo(); // Here you want the WickedlySmart version
} // But how will the compiler know?
}
To eliminate the confusion, you\'re required to do one of two things to help the
compiler:
1. Use an import statement,
import com.wickedlysmart.Foo;
class Bar {
void doStuff() {
Foo f = new Foo(); // Now the compiler knows which one to use
}
}
or
2. Use the fully qualified name throughout your code:
class Bar {
void doStuff() {
com.wickedlysmart.Foo f = new com.wickedlysmart.Foo() // No doubts
}
}