Commit 09d90f85 by Patryk Czarnik

Konstruktor i super()

parent bcfc1387
...@@ -32,6 +32,14 @@ public class PrzykladDziedziczenie { ...@@ -32,6 +32,14 @@ public class PrzykladDziedziczenie {
Konto kontoStudenckie = new Konto(1, 1000, student); Konto kontoStudenckie = new Konto(1, 1000, student);
System.out.println(kontoStudenckie); System.out.println(kontoStudenckie);
System.out.println();
// Konstruktory NIE SĄ automatycznie dziedziczone z nadklasy do podklasy.
// Student student2 = new Student("Marek", "Markowski", 23);
// Ale w podklasie można zdefiniować konstruktor, który inicjalizuje wszystko, co trzeba, częściowo za pomocą super(...)
Student student3 = new Student("Marek", "Markowski", 23, 3, "informatyka");
} }
} }
...@@ -8,6 +8,15 @@ public class Student extends Osoba { ...@@ -8,6 +8,15 @@ public class Student extends Osoba {
String kierunek; String kierunek;
List<Integer> oceny = new ArrayList<>(); List<Integer> oceny = new ArrayList<>();
Student() {
}
Student(String imie, String nazwisko, int wiek, int rok, String kierunek) {
super(imie, nazwisko, wiek);
this.rok = rok;
this.kierunek = kierunek;
}
void dodajOcene(int ocena) { void dodajOcene(int ocena) {
oceny.add(ocena); oceny.add(ocena);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment