Polymorphism: Difference between revisions
Content added Content deleted
Line 1,333: | Line 1,333: | ||
c.x //Evaluates to 12</lang> |
c.x //Evaluates to 12</lang> |
||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA |
ELENA 4.x : |
||
<lang elena>import extensions |
<lang elena>import extensions; |
||
class Point |
class Point |
||
{ |
{ |
||
int |
prop int X; |
||
int |
prop int Y; |
||
constructor |
constructor(int x, int y) |
||
{ |
|||
X := x; |
|||
Y := y |
|||
} |
|||
constructor |
constructor() |
||
<= |
<= (0,0); |
||
print |
print() { console.printLine("Point") } |
||
} |
} |
||
class Circle |
class Circle : Point |
||
{ |
{ |
||
int |
prop int R; |
||
constructor |
constructor() |
||
<= |
<= (0); |
||
constructor |
constructor(int r) |
||
<= |
<= (0, 0, r); |
||
constructor |
constructor(int x, int y, int r) |
||
<= |
<= (x, y) |
||
{ |
|||
R := r |
|||
} |
|||
print |
print() { console.printLine("Circle") } |
||
} |
} |
||
public program |
public program() |
||
{ |
|||
[ |
|||
Point p := new Point(); |
|||
Point c := new Circle(); |
|||
p |
p.print(); |
||
c |
c.print() |
||
}</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |