Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: A question about a few variables in a class Date: Sat, 06 Aug 2011 07:56:47 -0400 Organization: A noiseless patient Spider Lines: 40 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 6 Aug 2011 11:57:23 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="f8igmItKsWs6nM5YanFxAA"; logging-data="16698"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18xDMJm1LCnhHzxleOy78hK" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20110624 Thunderbird/5.0 In-Reply-To: Cancel-Lock: sha1:c5d8+gq5fwX5UKZtvxmoVQb2peY= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6825 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