Created
June 11, 2018 19:51
-
-
Save d630/341797b4b14593757390a35a94725e88 to your computer and use it in GitHub Desktop.
Vererbung 1
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; | |
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(); | |
} | |
} | |
} |
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