December 27, 2005 Difference by objekt initialisation | ||||
---|---|---|---|---|
| ||||
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? |
December 27, 2005 Re: Difference by objekt initialisation | ||||
---|---|---|---|---|
| ||||
Posted in reply to nobody | > 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 |
Copyright © 1999-2021 by the D Language Foundation