TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Classic View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Ben Brosgol <[log in to unmask]>
Fri, 17 Apr 1998 13:18:33 -0700
text/plain (42 lines)
Martin Carlyle wrote:

<<Near as I can tell, Java has NO multiple inheritance.  Yes, you can
test membership in more than one class hierarchy, but I didn't see a
way to inherit methods from more than one class.  I feel somewhat
silly mentioning this, since my best introduction to Java came from a
tutorial by Ben, so maybe he could enlighten me further if I am

I suspect that the C++ and Eiffel religious leaders would claim that Java
does not support multiple inheritance. It's a question of definition of
and if one regards mi as a good thing then one will want to define it to
include one's own language and exclude the competition :-).

You are right that Java allows a subclass to extend at most one superclass,
and in this sense Java only supports single inheritance.  However, through
the mechanism known as an interface -- which is in effect a stripped-down
class, e.g. with only abstract methods and only final variables
(constants) --
a subclass may extend one superclass and also"implement"  any number
of interfaces.  For example:

   class C1{ int f(){return 1}; }
   interface I1 { int g(); }  // g() is implicitly abstract
   interface I2 { double h(); }  // h is implicitly abstract

   class C2 extends C1 implements I1, I2{
      // implicitly inherit f() from C1
     int g(){ return 0; }
     int h(){ return 0.0; }

C2 may be regarded as "multiply inheriting" from C1, I1, and I2,
but only from C1 does it inherit any method implementations.

Whatever one chooses to call this mechanism, it is quite useful and is
widely exploited in the API.

Ben Brosgol
[log in to unmask]