Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36112
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: I don't understand why the following doesn't call Rectangle |
| Date | 2016-12-13 11:42 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <o2p8bq$7vd$1@dont-email.me> (permalink) |
| References | <45806188-ffb3-4173-aaf0-48c84655fa85@googlegroups.com> |
On 12/13/2016 10:42 AM, cdalten@gmail.com wrote:
> In the following lines of code....
>
>
> public class ComparableRectangle extends Rectangle
> implements Comparable<ComparableRectangle> {
> /** Construct a ComparableRectangle with specified properties */
> public ComparableRectangle(double width, double height) {
> super(width, height);
> }
>[...]
>
> The author calls super() to construct a ComparableRectangle. How is this possible? Wouldn't super () invoke the Rectangle constructor, and thus construct a Rectangle?
Yes!
Keep in mind that a ComparableRectangle *is* a Rectangle -- a
specialized kind of Rectangle, but a Rectangle nonetheless. Since
it is a Rectangle, it has a "Rectangle aspect" or "Rectangle-ness"
that needs to be initialized. What piece of Java code initializes
the Rectangle-nature of things that are Rectangles? The Rectangle
constructor, of course.
Furthermore, a Rectangle *is* an Object, so the first thing
the Rectangle constructor does is invoke the Object constructor to
set up its Object-ness. An Object *isn't* anything more general,
so the Object constructor needn't invoke anything further up the
line: It just initializes the Object-nature and returns to the
Rectangle constructor. Which, in turn, initializes the Rectangle-
ness and returns to the ComparableRectangle constructor. Which
has nothing more to do (in this case), so it just returns, having
arranged to set up the ComparableRectangle-ness, the Rectangle-ness,
and the Object-ness of the new instance.
The ComparableRectangle constructor sets up a ComparableRectangle,
which is also a Rectangle, which is also an Object. All three, at
the same time.
--
esosman@comcast-dot-net.invalid
"Nobody ever went broke underestimating the intelligence of the
American public." -- HLM (paraphrased)
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
I don't understand why the following doesn't call Rectangle cdalten@gmail.com - 2016-12-13 07:42 -0800
Re: I don't understand why the following doesn't call Rectangle Eric Douglas <e.d.programmer@gmail.com> - 2016-12-13 07:52 -0800
Re: I don't understand why the following doesn't call Rectangle cdalten@gmail.com - 2016-12-13 08:06 -0800
Re: I don't understand why the following doesn't call Rectangle Eric Douglas <e.d.programmer@gmail.com> - 2016-12-13 08:20 -0800
Re: I don't understand why the following doesn't call Rectangle Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-12-13 11:42 -0500
Re: I don't understand why the following doesn't call Rectangle lewbloch@gmail.com - 2016-12-13 12:47 -0800
Re: I don't understand why the following doesn't call Rectangle Manuel Collado <m.collado@domain.invalid> - 2016-12-14 19:13 +0100
csiph-web