Skip to content

Instantly share code, notes, and snippets.

@philipp-spiess
Created February 22, 2012 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipp-spiess/1886679 to your computer and use it in GitHub Desktop.
Save philipp-spiess/1886679 to your computer and use it in GitHub Desktop.
Inheritance
using System;
namespace Inheritance
{
class Program
{
static void Main(string[] args)
{
Quadrat q = new Quadrat(123);
Console.WriteLine(q.GetDiagonale());
Console.ReadKey();
}
}
}
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();
}
}
}
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