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

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 file to a particular java file my doubt is that..does both import and extend as they are inherting..? || 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

Joined: Sep 18, 2000
Posts: 562

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

Joined: Oct 27, 2005
Posts: 19674

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.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: doubt with import and extends