Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33399
| From | Xue Feng <xf.lotus@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | How to write constructor for an abstarct class? |
| Date | 2015-12-28 20:44 +0800 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <n5ramk$6se$1@speranza.aioe.org> (permalink) |
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.
Back to comp.lang.java.programmer | Previous | Next — 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