This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread 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 OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP 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: 1056

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: 586

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: 19849

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
Don't get me started about those stupid light bulbs.
subject: doubt with import and extends