File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diiference betwwen importing a class and extends a class

 
swarupa patil
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranche
I like to know the difference between the importign a class and extending a class .
 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi above,

Your question is too vague. Please be specific.
Think of the word inheritance when extending the class which you dont get when importing.

Regards,
Jothi Shankar Kumar. S
 
Rajesh Kadle
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

'import'is used to tell the compiler where to look for a class defined in a package.

'extends' is used to inherit properties from a class. Class from which we inherit is called 'base'(parent) class and the resultant new class is called 'derived'(child) class.

Lets say class A is defined in package P,and you are writing a new class B in another package Q, where you want to
'extend' class A.

In this case you write the code as below:



As can be seen from above, 'import' is used to tell compiler where to look for class A and 'extends' is used to create a new class (here B) using an existing class (here B).

Hope I didnt confuse you.
[ October 11, 2006: Message edited by: Rajesh Kadle ]
 
Aniket Patil
Ranch Hand
Posts: 218
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

'import'is used to tell the compiler where to look for a class defined in a package.

I differ, import is more of a programming convenience, than a neccessity. Your program is very well off without the import statement.

For eg. instead of an import, you could very well have used the fully qualified named of the class as P.A wherever you need to refer to A.

An import in this case is only useful for referring the class A in package P by its simple name.

For example:

So you see, it works without an import too, with the right classpath of course!
[ October 11, 2006: Message edited by: Aniket Patil ]
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The import statement is a little bit like the path statement in operating systems. It just makes stuff available, it doesn't do anything to bring it into your program. The import statement has a negligable (zero?)performance overhead. It is not, and I repeat NOT like the include statement in C/C++, and is entirely different to the extends statement.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic