my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Import Statement Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Import Statement Question" Watch "Import Statement Question" New topic

Import Statement Question

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

But what exactly does it do ?
i tried to use List in the code and i got compiler error

OCPJP 6.0 93%
OCPJWCD 5.0 98%
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

It would import classes under the java package, if there were any. It's not recursive. List is under java.util, so it won't be found.

[My Blog]
All roads lead to JavaRanch
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446

I will elaborate what christophe has said

suppose you have a package called packageA and you have classes classA, classB, ClassC in that package
and you have another package called innerpackage that is in the packageA
and the contents of the innerpackage are innerclassA, innerclassB

and you have another class where you are importing some packages

so when you write
import packageA.*;

you are importing only classes provided in the packageA i.e. classA ,classB, and classC
the innerpackage classes are NOT imported

for importing them
you have to write specifically

import packageA.innerpackage.*
now your innerclassA and innnerclassB will get imported

hope this helps
happy preparation mohit

SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

thanks Prasad Kharkar ,

I agree. Here's the link:
subject: Import Statement Question
It's not a secret anymore!