*
The moose likes Java in General and the fly likes What happen when import the same package more than one time in the given class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "What happen when import the same package more than one time in the given class." Watch "What happen when import the same package more than one time in the given class." New topic
Author

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

Achyut Behera
Greenhorn

Joined: Mar 09, 2009
Posts: 17
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


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38487
    
  23
Have you tried it?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3498
    
  13
imports are only used by the java compiler, not by the JVM, so they will have no effect on how many classes are loaded.


Joanne
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

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.


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What happen when import the same package more than one time in the given class.