Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33400
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How to write constructor for an abstarct class? |
| Date | Mon, 28 Dec 2015 08:21:08 -0500 |
| Organization | A noiseless patient Spider |
| Lines | 47 |
| Message-ID | <n5rcra$teb$1@dont-email.me> (permalink) |
| References | <n5ramk$6se$1@speranza.aioe.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=gbk; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Mon, 28 Dec 2015 13:18:34 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="30155"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/YIH4KzM/9+ecNRlnFM3qL" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 |
| In-Reply-To | <n5ramk$6se$1@speranza.aioe.org> |
| Cancel-Lock | sha1:oVEVRiE5QfMLYcovkRxvssg6EBA= |
| Xref | csiph.com comp.lang.java.programmer:33400 |
Show key headers only | View raw
On 12/28/2015 7:44 AM, Xue Feng wrote:
> I have written a Shape class to test abstract class. My plan is to
> include two fields x and y to represent the coordinate of a shape, and
> add two constructors to initialize the coordinate. In addition, two
> abstract methods, namely getArea() and getPerimeter(), is included to
> calculate the area and perimeter of a shape respectively. The two
> methods will be overrided by subclass of Shape. The code is as follows:
>
> class Shape {
> int x, y;
>
> public Shape(int x, int y) {
> this.x = x;
> this.y = y;
> }
>
> public Shape() {
> this(0, 0);
> }
>
> public abstract double getArea();
> public abstract double getPerimeter();
> }
>
> While compiling, the second constructor
>
> public Shape() {
> this(0, 0);
> }
>
> will cause error. I am aware of that Shape is an abstract class, hence
> can not be instantiated. But, how can I write the constructor
> alternately? Thanks.
I see no problem with the constructor. What is "error" you get?
However, the code you posted has a problem: The class itself must be
declared `abstract' if it has abstract methods, as in
abstract class Shape { ...
Are you sure that the code you posted is the same code that gives
you trouble?
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to write constructor for an abstarct class? Xue Feng <xf.lotus@yahoo.com> - 2015-12-28 20:44 +0800
Re: How to write constructor for an abstarct class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-28 08:21 -0500
Re: How to write constructor for an abstarct class? Jan Burse <janburse@fastmail.fm> - 2015-12-28 19:20 +0100
Re: How to write constructor for an abstarct class? Jan Burse <janburse@fastmail.fm> - 2015-12-28 19:25 +0100
Re: How to write constructor for an abstarct class? Jan Burse <janburse@fastmail.fm> - 2015-12-28 19:28 +0100
Re: How to write constructor for an abstarct class? Lew <lewbloch@gmail.com> - 2015-12-28 10:40 -0800
Re: How to write constructor for an abstarct class? Eric Douglas <e.d.programmer@gmail.com> - 2015-12-28 10:42 -0800
Re: How to write constructor for an abstarct class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-28 14:29 -0500
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-28 22:26 +0100
Re: How to write constructor for an abstarct class? Eric Douglas <e.d.programmer@gmail.com> - 2015-12-28 13:37 -0800
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-28 22:47 +0100
Re: How to write constructor for an abstarct class? Eric Douglas <e.d.programmer@gmail.com> - 2015-12-28 13:58 -0800
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-28 23:06 +0100
Re: How to write constructor for an abstarct class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-28 17:43 -0500
Re: How to write constructor for an abstarct class? Lew <lewbloch@gmail.com> - 2015-12-28 15:14 -0800
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-29 15:02 +0100
Re: How to write constructor for an abstarct class? Arne Vajhøj <arne@vajhoej.dk> - 2015-12-29 15:37 -0500
Re: How to write constructor for an abstarct class? Arne Vajhøj <arne@vajhoej.dk> - 2015-12-29 15:28 -0500
Re: How to write constructor for an abstarct class? Arne Vajhøj <arne@vajhoej.dk> - 2015-12-29 15:21 -0500
Re: How to write constructor for an abstarct class? Arne Vajhøj <arne@vajhoej.dk> - 2015-12-29 15:22 -0500
Re: How to write constructor for an abstarct class? j4n bur53 <janburse@fastmail.fm> - 2015-12-29 16:24 +0100
csiph-web