www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Difference by objekt initialisation

reply nobody <nobody_member pathlink.com> writes:
Hello

import std.stdio;
private import std.c.time;
public abstract class Form {
protected double radius;
protected abstract double berechneFlaeche();
}


public class Kreis : Form {
public double berechneFlaeche() {
return 3.14 * this.radius * this.radius;
}
}

int main( char[][] arg ) {
//Form kreis = new Kreis();
Kreis kreis = new Kreis();
kreis.radius=2.0;
writefln("Kreisflaeche = %f",kreis.berechneFlaeche());

return 0;
}

I can instantiate kreis with
Form kreis = new Kreis();
and 
Kreis kreis = new Kreis();
I get the same output:
Kreisflaeche = 12.560000

Is there any difference to do that?
Dec 27 2005
parent Frank Benoit <frank_DELETE_ _DELETE_drealtime.com> writes:
 I can instantiate kreis with
 Form kreis = new Kreis();
 and
 Kreis kreis = new Kreis();
 I get the same output:
 Kreisflaeche = 12.560000
 
 Is there any difference to do that?
No there is no difference in initialization. Only the "new Kreis()" is the initialization. The assignment is only an assignment of a reference with an optional/implicite cast. Frank -- D goes real-time: http://www.drealtime.com
Dec 27 2005