Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36112

Re: I don't understand why the following doesn't call Rectangle

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
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 Tue, 13 Dec 2016 11:42:52 -0500
Organization A noiseless patient Spider
Lines 42
Message-ID <o2p8bq$7vd$1@dont-email.me> (permalink)
References <45806188-ffb3-4173-aaf0-48c84655fa85@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Tue, 13 Dec 2016 16:41:30 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="a700588d24308dff6cdbdc832c4ad3b2"; logging-data="8173"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iNTqFV0RCqKM5tFcrnP+N"
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1
In-Reply-To <45806188-ffb3-4173-aaf0-48c84655fa85@googlegroups.com>
Cancel-Lock sha1:S9TyOUBXCius8VUJBXoccJkkWRY=
Xref csiph.com comp.lang.java.programmer:36112

Show key headers only | View raw


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


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