Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes A question came to my mind??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A question came to my mind???" Watch "A question came to my mind???" New topic

A question came to my mind???

Ammar Salem
Ranch Hand

Joined: Dec 29, 2007
Posts: 60
When we use Import statement in java, we simplay invoke a class from a certain package,that is fine with me,but this question keeps coming to my mind.IS IMPORTING A CLASS FROM A CERTAIN PACKAGE A KIND OF INHERITANCE??.I mean, is this statement " import java.util.Math ( I dont know wheather math class is in Util or not, but i am just giving an example),is that statement equal to this statement, say, public class MyMath extends Math, In conclusion, is Importing a type of Inheritance???

I hope I put my question right.
thank you.

****************************<br />For Some Dreams.....<br />One Lifetime Is Not Enough.<br />****************************
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 354

No. Importing is just telling the compiler where to find the class which you have used.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20273

Importing is basically programmers being lazy.

Without imports, you must write java.util.List, javax.swing.JFrame, etc. That is, with the full package.

Now import simply tells the compiler: if you encounter List, you should look for java.util.List. If you encounter JFrame, you should look for javax.swing.JFrame. If you encounter class X, look in package, or java.util.

How To Ask Questions How To Answer Questions
Qussay Najjar
Ranch Hand

Joined: Jan 18, 2008
Posts: 53
Many Java beginners think that import statement is to get the class you're using into your program which wrong for sure.
using import statement is only giving the path of that class to use its methods into your own class.

I agree. Here's the link:
subject: A question came to my mind???
It's not a secret anymore!