This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes doubt with import and extends Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "doubt with import and extends" Watch "doubt with import and extends" New topic
Author

doubt with import and extends

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

i have heard that extends acts as a type of inheritence and import on the other hand imports...java file to a particular java file

..so my doubt is that..does both import and extend as they are inherting..?


http://www.lifesbizzare.blogspot.com || OCJP:81%
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
They have nothing in common ... 'extends' acts for inheritance. The import statements simply define which packages, classes, etc. you want to use in your class.

If you want to work with the Date object, you need to import java.util.Date. That does not mean you inherit it's behavior.


JDBCSupport - An easy to use, light-weight JDBC framework -
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 562
    
    7

Import does no such thing. It allows you to access items of packages without prefixing with the package name - like it was local to your class
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Steve is right. You can change any working Java program to work without imports - you will just have to write out each class name with their package names as well. So instead of "Date date = new Date();" you would have to write "java.util.Date date = new java.util.Date();". In the end, import statements are only meant to make life easier for us programmers.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt with import and extends