Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. using System;
  2.  
  3. class Base
  4. {
  5. virtual public void who()
  6. {
  7. Console.WriteLine("Metoda w klase Base");
  8. }
  9. }
  10. class Derived1 : Base
  11. {
  12. override public void who()
  13. {
  14. Console.WriteLine("Metoda w kalsie der1");
  15. }
  16. }
  17.  
  18. class Derived2 : Derived1
  19. {
  20. //gdy metoda jest zakomentowana uruchomi sie metoda z klasy base
  21. override public void who()
  22. {
  23. Console.WriteLine("Metoda w kalsie der2");
  24. }
  25. }
  26.  
  27. class Derived3 : Derived2
  28. {
  29. //override public void who()
  30. //{
  31. // Console.WriteLine("Metoda w kalsie der3");
  32. //}
  33. }
  34.  
  35. //zadanie 3
  36. //metody zostano wywolanez klasy der1
  37. class demo
  38. {
  39. public static void Main()
  40. {
  41. Base baseob = new Base();
  42. Derived1 ob1 = new Derived1();
  43. Derived2 ob2 = new Derived2();
  44. Derived3 ob3 = new Derived3();
  45.  
  46. Base objref = baseob;
  47. objref.who();
  48.  
  49. objref = ob1;
  50. objref.who();
  51.  
  52. objref = ob2;
  53. objref.who();
  54.  
  55. objref = ob3;
  56. objref.who();
  57.  
  58. Console.ReadKey();
  59. }
  60. }
  61.  
  62. //abstract class TwoD
  63. //{
  64. // public int wysokosc;
  65. // public int szerokosc;
  66.  
  67. // abstract public int Area();
  68.  
  69. // public void set(int w, int h)
  70. // {
  71. // wysokosc = w;
  72. // szerokosc = h;
  73. // }
  74. //}
  75.  
  76. //class Tri : TwoD
  77. //{
  78. // override public int Area()
  79. // {
  80. // return wysokosc * szerokosc / 2;
  81. // }
  82. //}
  83.  
  84. //class Rec : TwoD
  85. //{
  86. // override public int Area()
  87. // {
  88. // return wysokosc * szerokosc;
  89. // }
  90. //}
  91. //class Demo
  92. //{
  93. // public static void Main()
  94. // {
  95. // TwoD szejp;
  96. // Tri tr = new Tri();
  97. // Rec re = new Rec();
  98.  
  99. // tr.set(2, 4);
  100. // szejp = tr;
  101. // Console.WriteLine(szejp.Area());
  102.  
  103. // re.set(2, 4);
  104. // szejp = re;
  105. // Console.WriteLine(szejp.Area());
  106. // Console.ReadKey();
  107. // }
  108. //}
  109.  
  110. // class Box
  111. //{
  112. // public static void Main()
  113. // {
  114. // int x = 10;
  115. // Console.WriteLine(x);
  116. // x = sqr(x);
  117. // Console.WriteLine(x);
  118. // Console.ReadKey();
  119. // }
  120.  
  121. // static int sqr(object o)
  122. // {
  123. // return (int) o * (int) o;
  124. // }
  125. //}
  126.  
  127. //class Generic
  128. //{
  129. // public static void Main()
  130. // {
  131. // object[] ga = new object [10];
  132. // for (int i = 0; i < 3; i++)
  133. // {
  134. // int number = i + i * i;
  135. // ga[i] = number;
  136. // }
  137.  
  138. // for (int i = 3; i < 6; i++)
  139. // {
  140. // double number = (double)i/3;
  141. // ga[i] = number;
  142. // }
  143.  
  144. // ga[6] = "Tablica stringow";
  145. // ga[7] = true;
  146. // ga[8] = 'x';
  147. // ga[9] = "Koniec";
  148. //http://boards.4chan.org/trash/
  149. // for(int i =0;i<10;i++)
  150. // {
  151. // Console.WriteLine(ga[i]);
  152. // }
  153. // Console.ReadKey();
  154. // }
  155. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement