This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply 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: 32708
    
    4
Have you tried it?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3011
    
    9
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: 774

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: What happen when import the same package more than one time in the given class.
 
Similar Threads
Diagrammatic representation of inheritance.
Inheritance and Polymorphism
Confused with instanceof, please help
Following code shows ClassCastException
Superclass to Subclass Casting