This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 37926
    
  22
Have you tried it?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3419
    
  12
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
 
wood burning stoves
 
subject: What happen when import the same package more than one time in the given class.
 
Similar Threads
Superclass to Subclass Casting
Confused with instanceof, please help
Inheritance and Polymorphism
Diagrammatic representation of inheritance.
Following code shows ClassCastException