Facebook
From Capacious Prairie Dog, 7 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 268
  1. using static System.Console;
  2.  
  3. namespace Zad6_3
  4. {
  5.     class Program : Pro
  6.     {
  7.         public string ms1 = "To jest zmienna publiczna";
  8.  
  9.         public void print(string ms)
  10.         {
  11.             WriteLine($"Tu drukuję parametr: {ms}");
  12.         }
  13.         public void print(int i)
  14.         {
  15.             WriteLine("Ta metoda robi co innego - zwraca i*2");
  16.             WriteLine(i * 2);
  17.         }
  18.         static void Main(string[] args)
  19.         {
  20.             WriteLine("Abstrakcja");
  21.             WriteLine("Instancja klasy Human - nie da się utworzyć bezpośrednio");
  22.             //Human human = new Human();
  23.             WriteLine("Instancja klasy Student");
  24.             Student stud = new Student();
  25.             WriteLine("Czy obudzony: " + stud.awakeness());
  26.             stud.goToSleep();
  27.             WriteLine("Czy obudzony: " + stud.awakeness());
  28.             WriteLine();
  29.  
  30.             WriteLine("Hermetyzacja");
  31.             Pro pro = new Pro();
  32.             Program pub = new Program();
  33.             Pri pri = new Pri();
  34.             Inter inter = new Inter();
  35.             ProInc proInc = new ProInc();
  36.  
  37.             //WriteLine(pri.ms3);
  38.             WriteLine(pub.ms2 + ", do której mamy dostęp przez klasę dziedziczącą");
  39.             //WriteLine(pub.ms3 + ", do której mamy dostęp przez klasę dziedziczącą");
  40.             WriteLine();
  41.             WriteLine(inter.ms4 + ", dostęp poza klasą, poprzez obiekt");
  42.             WriteLine(proInc.ms5 + ", dostęp poza klasą, poprzez obiekt");
  43.  
  44.             WriteLine();
  45.             WriteLine("Dziedziczenie");
  46.             Cat cat = new Cat();
  47.             cat.setName("Filemon");
  48.             WriteLine(cat.name);
  49.             WriteLine(cat.talk());
  50.             WriteLine();
  51.  
  52.             WriteLine("Polimorfizm");
  53.             pub.print("Moja wiadomość");
  54.             pub.print(10);
  55.             Read();
  56.         }
  57.     }
  58.     abstract class Human
  59.     {
  60.         abstract public void goToSleep();
  61.     }
  62.     class Student
  63.     {
  64.         bool awaken = true;
  65.         public void goToSleep()
  66.         {
  67.             awaken = false;
  68.         }
  69.         public bool awakeness()
  70.         {
  71.             return awaken;
  72.         }
  73.     }
  74.  
  75.     class Pro : Pri
  76.     {
  77.         protected string ms2 = "To jest zmienna chroniona (protected)";
  78.     }
  79.     class Pri
  80.     {
  81.         private string ms3 = "To jest zmienna prywatna";
  82.         public string getPri()
  83.         {
  84.             return ms3;
  85.         }
  86.     }
  87.     class Inter
  88.     {
  89.         internal string ms4 = "To jest zmienna wewnętrzna (internal)";
  90.     }
  91.     class ProInc
  92.     {
  93.         protected internal string ms5 = "To jest zmienna chroniona wewnętrzna (protected internal)";
  94.     }
  95.  
  96.     public class Animal
  97.     {
  98.         public string name = "Mam na imię ";
  99.         public string setName(string name)
  100.         {
  101.             this.name += name;
  102.             return name;
  103.         }
  104.         public string roar()
  105.         {
  106.             return "";
  107.         }
  108.     }
  109.     public class Cat : Animal
  110.     {
  111.         public string talk()
  112.         {
  113.             return "Meow, meow";
  114.         }
  115.     }
  116. }
  117.