Polymorphism: Difference between revisions

Content added Content deleted
Line 440: Line 440:
=={{header|D}}==
=={{header|D}}==
<code>
<code>
import std.stdio;
import std.stdio;


class Point {
class Point {
int x, y;
int x, y;
this(int x0=0, int y0=0) { x = x0; y = y0; }
this(int x0=0, int y0=0) { x = x0; y = y0; }
int getX() { return x; }
int getX() { return x; }
void setX(int x) { this.x = x; }
void setX(int x) { this.x = x; }
int getY() { return y; }
int getY() { return y; }
void setY(int y) { this.y = y; }
void setY(int y) { this.y = y; }
}
}


class Circle : Point {
class Circle : Point {
int r;
int r;
this(int x0=0, int y0=0, int r0=0) { super(x0,y0); r=r0; }
this(int x0=0, int y0=0, int r0=0) { super(x0,y0); r=r0; }
this(Point p, int r0=0) { super(p.getX,p.getY); r = r0; }
this(Point p, int r0=0) { super(p.getX,p.getY); r = r0; }
int getR() { return r; }
int getR() { return r; }
void setR(int r) { this.r = r; }
void setR(int r) { this.r = r; }
}
}


void main() {
void main() {
auto p = new Point();
auto p = new Point();
auto c = new Circle();
auto c = new Circle();
writefln(p);
writefln(p);
writefln(c);
writefln(c);
}
}
</code>
</code>