Why to use inheritance when import is sufficient

The import directive tells the compiler where to look for the class definitions when it comes upon a class that it cannot find in the default java.lang package. After an import statement has been included in our program we can use the methods related to that class as required and we are not required to give the fully qualified names.

In inheritance we extend a base class into a derived class so that the features and methods of the base class are available in the derived class which facilitates reusability. As per my understanding the same thing is facilitated by import statements. If it is so, why are we using inheritance if it can be done with the use of import statements?

[695 byte] By [snmana] at [2007-11-26 19:39:02]
# 1

Import statements and inheritance are completely different things.

Import statements tell the compiler how to expand brief class names into fully-qualified class names. It has nothing to do with the functionality of the code.

Inheritance changes the identification and functionality of the classes, and thus the functionality of the code.

Maybe you're really thinking about composition/delegation vs. inheritance. Composition is when a class has another class as a part of it, and delegation is when the class sends some of its work to the other class. You can have an object-oriented system without inheritance of implementations, using composition instead.

paulcwa at 2007-7-9 22:17:45 > top of Java-index,Java Essentials,Java Programming...
# 2

Very true but still I have some doubt. When we import a class we can use the functions defined in that class in our code. When we use inheritance again we are extending the functionality and we can use the functions defined for the parent class in the child class. In both the cases we are using the functionality which is already available with us. so whats the diff?

snmana at 2007-7-9 22:17:45 > top of Java-index,Java Essentials,Java Programming...
# 3
Inheritance isn't used to get functionality from other classes. It's used to extend a classes functionality and simplify code. Read up on object oriented programming and you'll eventually understand.
-Kayaman-a at 2007-7-9 22:17:45 > top of Java-index,Java Essentials,Java Programming...