Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the difference between importing and the extending statements

 
leela sundar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can any one say the difference between importing and the extending statements
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
leela sundar wrote:can any one say the difference between importing and the extending statements


what you mean by extending statements, you mean extending class?
 
Sujai Kaarthik
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need to use some of the predefined classes of the API in your class and extend the capabilities of the same class then you have to use import. With out importing a package or a class you cannot extend or inherit the properties and methods of a class.

Someone correct me if I am wrong
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to go out on a limb and say that I think he was asking what's the different between implements and extends, because they look similar



The difference is that you can extend one other class, and you can implement any number of interfaces. Extending a class means inheriting all its methods, and adding to them and possibly overriding some of them; implementing an interface means that you have to supply all the methods declared in the interface. In both cases, your class becomes a subtype of the class or interface, so that if a method asks for a SuperClass or SomeInterface instance, you can pass a Foo instance and it will work.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50240
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An import statement instructs the compiler where to find a class which you are using.
 
priya rishi
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am assuming that you asked difference between import and extends keyword .

extends keyword achieves use of inheritance in java.

purpose of inheritance - resuse of code from elsewhere(from class which might be in same package or else in different package)

1.if class is in same package:

a. all you need to do is simply use extends keyword to extend/inherit the class.

2.if class is in different package:

a.must import package in which the class is available using import keyword.
b.then extend the class using extends keyword.

note:
1.you can import more than one packages in your class depending upon your requirement.
2.you must extend only one class as java does support multilevel inheritance ,does not support multiple inheritance(using implements keyword we can implement more than one interface.)

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic