Skip to content

Instantly share code, notes, and snippets.

@d630
Created June 11, 2018 19:51
Show Gist options
  • Save d630/341797b4b14593757390a35a94725e88 to your computer and use it in GitHub Desktop.
Save d630/341797b4b14593757390a35a94725e88 to your computer and use it in GitHub Desktop.
Vererbung 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace csharp
{
public class Person
{
private string vorname;
private string nachname;
public Person (string vorname, string nachname)
{
this.vorname = vorname;
this.nachname = nachname;
}
public void who()
{
Console.WriteLine(this.vorname + " " + this.nachname);
}
}
public class Schueler : Person
{
private char klasse;
public Schueler(string vorname, string nachname, char klasse) : base(vorname, nachname)
{
this.klasse = klasse;
}
}
public class Lehrer : Person
{
private string fach;
public Lehrer(string vorname, string nachname, string fach) : base(vorname, nachname)
{
this.fach = fach;
}
}
public class Program
{
static void Main(string[] args)
{
Lehrer l = new Lehrer("mahatma", "gandhi", "protest");
Schueler s = new Schueler("mahatma", "gandhi jr.", 'A');
l.who();
s.who();
}
}
}
@d630
Copy link
Author

d630 commented Jun 11, 2018

  • kein super(), sondern base()
  • kein extends, sondern :

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment