digitalmars.D.learn - Difference by objekt initialisation
- nobody (26/26) Dec 27 2005 Hello
- Frank Benoit (6/14) Dec 27 2005 No there is no difference in initialization. Only the "new Kreis()" is t...
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
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