Created
February 22, 2012 19:04
-
-
Save philipp-spiess/1886679 to your computer and use it in GitHub Desktop.
Inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Inheritance | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Quadrat q = new Quadrat(123); | |
Console.WriteLine(q.GetDiagonale()); | |
Console.ReadKey(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Inheritance | |
{ | |
class Quadrat : Rechteck | |
{ | |
static double WURZEL2 = Math.Sqrt(2); | |
public Quadrat(double laenge) : base(laenge, laenge) | |
{ | |
} | |
public override double GetDiagonale () | |
{ | |
return WURZEL2 * GetLaenge(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Inheritance | |
{ | |
class Rechteck | |
{ | |
private double laenge; | |
private double breite; | |
public Rechteck(double laenge, double breite) | |
{ | |
this.laenge = laenge; | |
this.breite = breite; | |
} | |
public double GetLaenge() | |
{ | |
return this.laenge; | |
} | |
public double GetBreite() | |
{ | |
return this.breite; | |
} | |
public double GetUmfang() | |
{ | |
return 2 * this.laenge + 2 * this.breite; | |
} | |
public virtual double GetDiagonale() | |
{ | |
return Math.Sqrt(this.laenge * this.laenge + this.breite * this.breite); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment