Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!m5g2000prh.googlegroups.com!not-for-mail From: Chad Newsgroups: comp.lang.java.programmer Subject: Re: A question about a few variables in a class Date: Sat, 13 Aug 2011 10:30:48 -0700 (PDT) Organization: http://groups.google.com Lines: 51 Message-ID: <8ff5e4fa-84c5-4d4a-97e8-0b2f3f5b0dc4@m5g2000prh.googlegroups.com> References: NNTP-Posting-Host: 66.81.41.11 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1313256763 10652 127.0.0.1 (13 Aug 2011 17:32:43 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 13 Aug 2011 17:32:43 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: m5g2000prh.googlegroups.com; posting-host=66.81.41.11; posting-account=kTs1ygoAAACgG1TSoyECpovEyy-V6_8b User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2),gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7087 On Aug 6, 4:56=A0am, Eric Sosman wrote: > On 8/5/2011 5:31 PM, Chad wrote: > > > > > > > Let's say I have the following class..... > > > public class ComparableRectangle extends Rectangle implements > > Comparable { > > =A0 =A0public ComparableRectangle(double width, double height) { > > =A0 =A0 =A0super(width, height); > > =A0 =A0} > > > =A0 =A0public int compareTo(Object o) { > > =A0 =A0 =A0if (getArea()> =A0((ComparableRectangle)o).getArea()) > > =A0 =A0 =A0 =A0return 1; > > =A0 =A0 =A0else if (getArea()< =A0((ComparableRectangle)o).getArea()) > > =A0 =A0 =A0 =A0return -1; > > =A0 =A0 =A0else > > =A0 =A0 =A0 =A0return 0; > > =A0 =A0} > > } > > > 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. > > =A0 =A0 =A0Looking only at the snippet shown, it's impossible to answer > the question. =A0The ComparableRectangle class itself has no members > named width or height. =A0It might (or might not) inherit such > members from Rectangle or from a superclass of Rectangle. =A0All 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. > > =A0 =A0 =A0We don't actually know what Rectangle is because there are no > import statements to tell us what package it's in. =A0It clearly > cannot be java.awt.Rectangle, which has public width and height > members but which has no getArea() and no suitable constructor. > Aye. I broke away from my own personal rule of posting code snippets. I should know better since it really annoys me when people post code snippets on comp.lang.c, and then, like magic, expect the group to be able to magically interpet their line of thought. Chad