using static System.Console; namespace Zad6_3 { class Program : Pro { public string ms1 = "To jest zmienna publiczna"; public void print(string ms) { WriteLine($"Tu drukuję parametr: {ms}"); } public void print(int i) { WriteLine("Ta metoda robi co innego - zwraca i*2"); WriteLine(i * 2); } static void Main(string[] args) { WriteLine("Abstrakcja"); WriteLine("Instancja klasy Human - nie da się utworzyć bezpośrednio"); //Human human = new Human(); WriteLine("Instancja klasy Student"); Student stud = new Student(); WriteLine("Czy obudzony: " + stud.awakeness()); stud.goToSleep(); WriteLine("Czy obudzony: " + stud.awakeness()); WriteLine(); WriteLine("Hermetyzacja"); Pro pro = new Pro(); Program pub = new Program(); Pri pri = new Pri(); Inter inter = new Inter(); ProInc proInc = new ProInc(); //WriteLine(pri.ms3); WriteLine(pub.ms2 + ", do której mamy dostęp przez klasę dziedziczącą"); //WriteLine(pub.ms3 + ", do której mamy dostęp przez klasę dziedziczącą"); WriteLine(); WriteLine(inter.ms4 + ", dostęp poza klasą, poprzez obiekt"); WriteLine(proInc.ms5 + ", dostęp poza klasą, poprzez obiekt"); WriteLine(); WriteLine("Dziedziczenie"); Cat cat = new Cat(); cat.setName("Filemon"); WriteLine(cat.name); WriteLine(cat.talk()); WriteLine(); WriteLine("Polimorfizm"); pub.print("Moja wiadomość"); pub.print(10); Read(); } } abstract class Human { abstract public void goToSleep(); } class Student { bool awaken = true; public void goToSleep() { awaken = false; } public bool awakeness() { return awaken; } } class Pro : Pri { protected string ms2 = "To jest zmienna chroniona (protected)"; } class Pri { private string ms3 = "To jest zmienna prywatna"; public string getPri() { return ms3; } } class Inter { internal string ms4 = "To jest zmienna wewnętrzna (internal)"; } class ProInc { protected internal string ms5 = "To jest zmienna chroniona wewnętrzna (protected internal)"; } public class Animal { public string name = "Mam na imię "; public string setName(string name) { this.name += name; return name; } public string roar() { return ""; } } public class Cat : Animal { public string talk() { return "Meow, meow"; } } }