Commit 4a674a2a by Patryk Czarnik

Klasa Student - początek

parent 88fecb73
package p10_klasy.v4;
public class PrzykladDziedziczenie {
public static void main(String[] args) {
Osoba osoba = new Osoba();
// Obiekt klasy Osoba posida tylko te pola i metody, które zostały zdefiniowane w klasie Osoba
osoba.imie = "Ala";
osoba.nazwisko = "Kowalska";
osoba.wiek = 30;
osoba.przedstawSie();
// Obiekt klasy Student posiada pola i metody pochodzące z klasy Osoba,
// a dodatkowo te pola i metody, które zostały dodefiniownae w klasie Student.
Student student = new Student();
student.imie = "Adam";
student.nazwisko = "Abacki";
student.wiek = 21;
student.rok = 2;
student.kierunek = "medycyna";
student.przedstawSie();
student.dodajOcene(4);
student.dodajOcene(5);
System.out.println("Średnia ocen: " + student.sredniaOcen());
Sklep zabka = new Sklep("Żabka", 6);
zabka.sprzedajPiwo(student);
}
}
package p10_klasy.v4;
public class Student extends Osoba {
int rok;
String kierunek;
void dodajOcene(int ocena) {
// TODO
}
double sredniaOcen() {
return 4.5;
}
}
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