File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 1076

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

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

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
It's not a secret anymore!