Re: Types of inheritance

From: Fu, Ren-Li (frl8_at_rogers.com)
Date: 10/18/03


Date: Sat, 18 Oct 2003 18:36:23 GMT


"Chris Smith" <cdsmith@twu.net> wrote in message
news:MPG.19faef0ee097cc4c989702@news.pop4.net...
> Fu, Ren-Li wrote:
> > Another reason I dont like implementation inheritance is because you
have to
> > reproduce code, don't you? Maybe you want all derived objects to have
the
> > same core default state. Don't you have to *cut and paste* the
constructor
> > code then?
>
> No. Whenever an instance of a derived class is created, the constructor
> chains a call (implicitly or explicitly) to the superclass. If the
> superclass has a constructor that initializes the state of the object,
> then the derived class will always have its inherited state initialized.

I meant to say interface inheritance. Becase no implementation is inherrited
(sorry for the confusion).

As for explicit chaining, this is not true in implementation inheritance.

If it is please clarify this. But I have a class NWObject which prints a
message in its constructor, and class Monster extends NWObject does not
print the same message unless it explicitly calls super(). That's
implementation inheritance for you. I don't know why I need to call super(),
but maybe its a good thing. What about interface inheritance? My original
question was if I would need to cut and paste since no implementation is
inherrited..

-frl



Relevant Pages

  • Re: Types of inheritance
    ... > Another reason I dont like implementation inheritance is because you have to ... > reproduce code, don't you? ... Maybe you want all derived objects to have the ... chains a call to the superclass. ...
    (comp.lang.java.help)
  • Re: Types of inheritance
    ... Another reason I dont like implementation inheritance is because you have to ... reproduce code, don't you? ... Maybe you want all derived objects to have the ... same core default state. ...
    (comp.lang.java.help)