This week's book giveaway is in the Java in General forum.
We're giving away four copies of Java by Comparison (eBook) and have Simon Harrer, Jörg Lenhard, Linus Dietz on-line!
See this thread for details.
Win a copy of Java by Comparison (eBook) this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What happen when import the same package more than one time in the given class.  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Suppose i have a class name "Animal" in some package;
and one more class "Dog" in some other packages.

What happens if i import the animal class more than one time in Dog class.
The animal class will be loaded twice or what?
Please tell me internally what happens?

Thanks,
Achyut


 
Sheriff
Posts: 57797
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
imports are only used by the java compiler, not by the JVM, so they will have no effect on how many classes are loaded.
 
Ranch Hand
Posts: 802
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know the meaning of import statement then you will know what happens if you import the animal class more than one time in Dog class.

The class using import statement

You can use just File

Same class without using import statement
You have to use fully qualified java class name


The import means you don't have to write fully quallified java class name.
Its for our convinience to use in coding.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!