aspose file tools*
The moose likes Beginning Java and the fly likes what is the difference between importing and the extending statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is the difference between importing and the extending statements" Watch "what is the difference between importing and the extending statements" New topic
Author

what is the difference between importing and the extending statements

leela sundar
Greenhorn

Joined: Jan 08, 2009
Posts: 1
can any one say the difference between importing and the extending statements
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Dec 29, 2008
Posts: 162
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

The greater danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
An import statement instructs the compiler where to find a class which you are using.
priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
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.)



SCJP 5 , SCWCD 5
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: what is the difference between importing and the extending statements