Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Importing a class

 
Prathima gaitonde
Ranch Hand
Posts: 130
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In the above code Test is the class within com/oracle/certification/exceptionexamples package.

I am trying to find out the usage of import statement here.
Is there any difference between Line1 and Line2 ?
If yes then, what is the difference?

Secondly,

Which is/are the implicit import statement(s) in my above program?
 
Maneesh Godbole
Saloon Keeper
Posts: 11329
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prathima gaitonde wrote:
I am trying to find out the usage of import statement here.
Is there any difference between Line1 and Line2 ?
If yes then, what is the difference?...
Which is/are the implicit import statement(s) in my above program?

Recommended reading https://docs.oracle.com/javase/tutorial/java/package/usepkgs.html
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prathima gaitonde wrote:Is there any difference between Line1 and Line2 ?
If yes then, what is the difference?

Yes, there is a huge difference between line1 and line2!
  • line2 is the import statement for class Test
  • line1 will not import class Test, but will import all public nested classes of class Test


  • To import a whole package, use import com.oracle.certification.exceptionexamples.*;

    Prathima gaitonde wrote:Which is/are the implicit import statement(s) in my above program?

    All classes from the package java.lang (e.g. System) are implicitly imported.

    Hope it helps!
    Kind regards,
    Roel

    (Disclaimer: for the OCAJP7 exam you don't need to know what nested classes are; it's an exam objective of the OCPJP7 exam)
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic