Answer:

Yes. But this leads to problems.

Problems with Hacking Code

If you have the source code for a class, you could copy the code and change it to do what you wanted. Before object oriented programming that was what was done. But there are at least two problems with this:

class B isa class A

(i) It is hard to stay organized. Say that you already have several dozen classes and that you need additional classes based on the original ones. Also, say that you need several classes based on the new classes. You will end up with dozens of source files which are all versions of other source files that have been changed in various ways. Without careful planning you will end up with an unorganized, inconsistent, buggy mess.

(ii) You need to study the original code. Say that you have a complicated class that basically does what you want, but you need a small modification. If you edit the source code, even to make a small change, you risk breaking something. So you must study the original code to be sure that your changes are correct. This may not be easy.

The automatic inheritance mechanism of Java greatly relieves both of these problems.

In diagrams that show inheritance, an arrow points from the new class to the class it is based upon. The arrow is sometimes labeled "is a".

In these notes, clouds represent classes and rectangles represent objects. This style of representing classes comes from the book Object-oriented Analysis and Design, by Grady Booch (Addison-Wesley, 1994). In official UML (Unified Modeling Language) both classes and objects are represented with rectangles.

QUESTION 2:

Say that class B is based upon class A. Which one would you call the parent class? Which one would you call the child class?