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


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

Re: A question about a few variables in a class

From Eric Sosman <esosman@ieee-dot-org.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: A question about a few variables in a class
Date 2011-08-06 07:56 -0400
Organization A noiseless patient Spider
Message-ID <j1ja73$g9q$1@dont-email.me> (permalink)
References <c5422014-46bd-4c77-9302-839b5cb587a2@a2g2000prf.googlegroups.com>

Show all headers | View raw


On 8/5/2011 5:31 PM, Chad wrote:
> Let's say I have the following class.....
>
>
> public class ComparableRectangle extends Rectangle implements
> Comparable {
>    public ComparableRectangle(double width, double height) {
>      super(width, height);
>    }
>
>    public int compareTo(Object o) {
>      if (getArea()>  ((ComparableRectangle)o).getArea())
>        return 1;
>      else if (getArea()<  ((ComparableRectangle)o).getArea())
>        return -1;
>      else
>        return 0;
>    }
> }
>
> Are 'width' and 'height' data fields in this class? My initial guess
> is yes. However, the fact that they are passed to super() makes me
> wonder otherwise.

     Looking only at the snippet shown, it's impossible to answer
the question.  The ComparableRectangle class itself has no members
named width or height.  It might (or might not) inherit such
members from Rectangle or from a superclass of Rectangle.  All we
can be sure of is (1) Rectangle has a constructor taking two
double arguments, and (2) Rectangle or a Rectangle ancestor has
a getArea() method returning a primitive number of some kind.

     We don't actually know what Rectangle is because there are no
import statements to tell us what package it's in.  It clearly
cannot be java.awt.Rectangle, which has public width and height
members but which has no getArea() and no suitable constructor.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

A question about a few variables in a class Chad <cdalten@gmail.com> - 2011-08-05 14:31 -0700
  Re: A question about a few variables in a class markspace <-@.> - 2011-08-05 14:46 -0700
  Re: A question about a few variables in a class Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-06 07:56 -0400
    Re: A question about a few variables in a class Chad <cdalten@gmail.com> - 2011-08-13 10:30 -0700
      Re: A question about a few variables in a class Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-13 20:49 -0400
        Re: A question about a few variables in a class Chad <cdalten@gmail.com> - 2011-08-14 13:23 -0700
          Re: A question about a few variables in a class markspace <-@.> - 2011-08-14 13:52 -0700
            Re: A question about a few variables in a class Lew <lewbloch@gmail.com> - 2011-08-14 22:50 -0700
          Re: A question about a few variables in a class Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-14 18:04 -0400
            Re: A question about a few variables in a class Chad <cdalten@gmail.com> - 2011-08-14 17:09 -0700
              Re: A question about a few variables in a class Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-14 21:57 -0400
              Re: A question about a few variables in a class Lew <lewbloch@gmail.com> - 2011-08-14 22:55 -0700
          Re: A question about a few variables in a class Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-14 18:01 -0400
  Re: A question about a few variables in a class Roedy Green <see_website@mindprod.com.invalid> - 2011-08-06 22:58 -0700
    Re: A question about a few variables in a class Patricia Shanahan <pats@acm.org> - 2011-08-07 05:28 -0700
  Re: A question about a few variables in a class Lew <lewbloch@gmail.com> - 2011-08-10 09:14 -0700
    Re: A question about a few variables in a class Chad <cdalten@gmail.com> - 2011-08-13 10:27 -0700
  Re: A question about a few variables in a class Patricia Shanahan <pats@acm.org> - 2011-08-14 18:36 -0700

csiph-web