mirror of
https://github.com/pepaskopec-blip/Graduately.git
synced 2026-10-27 15:14:35 +00:00
Add a C# course with a side-by-side code runner.
Each lesson explains a topic and runs the edited program next to the text through the local .NET SDK. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
6662eb185e
commit
333085ee53
86 changed files with 2482 additions and 5 deletions
52
content/programovani/3-rocnik/05-dedicnost.md
Normal file
52
content/programovani/3-rocnik/05-dedicnost.md
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
id: cs-3-dedicnost
|
||||
nazev: Dědičnost
|
||||
popis: Nová třída převezme hotovou.
|
||||
---
|
||||
|
||||
# Výklad
|
||||
|
||||
## base
|
||||
*: Zak*
|
||||
|
||||
- class Student : Zak znamená, že student je žák a má něco navíc.
|
||||
- Dostane Jmeno a Vek, aniž by se psaly znovu.
|
||||
- base(...) zavolá konstruktor předka.
|
||||
|
||||
> Tip: Student umí to, co Zak, a ještě obor.
|
||||
|
||||
## Je
|
||||
*typ*
|
||||
|
||||
- Student lze uložit do proměnné Zak. Pořád je to student.
|
||||
- Opačně žák bez oboru studentem není.
|
||||
- Na specialitu sáhnete, až když máte původní typ.
|
||||
|
||||
> Tip: Vypište i obor. Patří studentovi, ne obecnému žákovi.
|
||||
|
||||
# Kód
|
||||
|
||||
```
|
||||
Student s = new Student("Eva", 18, "informatika");
|
||||
Console.WriteLine($"{s.Jmeno}, {s.Obor}");
|
||||
|
||||
class Zak
|
||||
{
|
||||
public string Jmeno { get; set; }
|
||||
public int Vek { get; set; }
|
||||
public Zak(string jmeno, int vek)
|
||||
{
|
||||
Jmeno = jmeno;
|
||||
Vek = vek;
|
||||
}
|
||||
}
|
||||
|
||||
class Student : Zak
|
||||
{
|
||||
public string Obor { get; set; }
|
||||
public Student(string jmeno, int vek, string obor) : base(jmeno, vek)
|
||||
{
|
||||
Obor = obor;
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue