44 lines
707 B
C#
44 lines
707 B
C#
|
|
namespace Tag_3_Unterricht;
|
||
|
|
|
||
|
|
public class Vererbung
|
||
|
|
{
|
||
|
|
public static void Main()
|
||
|
|
{
|
||
|
|
var auto = new Auto();
|
||
|
|
var auto2 = new Auto("Orange");
|
||
|
|
|
||
|
|
Console.WriteLine(auto.lackfarbe);
|
||
|
|
Console.WriteLine(auto.preis);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class Produkt
|
||
|
|
{
|
||
|
|
public int preis;
|
||
|
|
|
||
|
|
public Produkt(int preis)
|
||
|
|
{
|
||
|
|
this.preis = preis;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class Auto : Produkt
|
||
|
|
{
|
||
|
|
public string lackfarbe;
|
||
|
|
|
||
|
|
public Auto() : this("UNBEMALT")
|
||
|
|
{
|
||
|
|
Console.WriteLine("Auto ohne Lack erstellt");
|
||
|
|
}
|
||
|
|
|
||
|
|
public Auto(string lackfarbe) : base(100)
|
||
|
|
{
|
||
|
|
einfärben(lackfarbe);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void einfärben(string lackfarbe)
|
||
|
|
{
|
||
|
|
this.lackfarbe = lackfarbe;
|
||
|
|
}
|
||
|
|
}
|