• Post Reply Bookmark Topic Watch Topic
  • New Topic

Import versus Extend  RSS feed

 
Mrinal Roy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we extend a class it is obvious that the members (of superclass) are implemented in the subclass. Also if we import a class(of a package) we can use its public methods (as if the importing methods are implemented in the current class itself).

Then how does import differ from extend in its functionality?
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
extend says this class is super class of current class.

import says this class is in this location or this namespace.

For Example,





[ December 08, 2006: Message edited by: Prabhu venkatachalam ]
 
Divya Shastry
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

A class which extends from a super class can access the methods which have access modifier of "protected" type, even though the superclass is in a separate package than the sub class.

But when a class in a different package is imported, it's "protected" members cannot be accessed by the class which is importing it.

I hope I am right, because I am also in the learning process !
 
John Bartlett
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take into consideration you can only extend one superclass and how many imports you use on even the smallest program.

John
 
Mrinal Roy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see the things clearer. Thanks to Prabhu, Divya and John.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!