Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question came to my mind???

 
Ammar Salem
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abhinav Srivastava
Ranch Hand
Posts: 354
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Importing is just telling the compiler where to find the class which you have used.
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 java.io, java.net or java.util.
 
Qussay Najjar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic