fork download
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. B b = new B(); // Делаю ссылку на класс B
  8.  
  9. Console.WriteLine(b.new_age); // Вывожу в консоль переменную new_age из класса B
  10. Console.WriteLine(b.age);
  11. Console.ReadKey();
  12. }
  13. }
  14.  
  15. class A
  16. {
  17. public int age = 20; // Создаю протектед переменную со значением 20
  18.  
  19. public A(){
  20. Console.WriteLine("Actor");
  21. }
  22. }
  23.  
  24. class B : A // Создаю класс B который наследуется от класса A
  25. {
  26. public int new_age; // Создаю публичную переменную new_age
  27.  
  28. public B() // Создаю публичный метод
  29. {
  30. Console.WriteLine("Bctor");
  31. new_age = age; // В методе говорю что новая переменная new_age равна переменной age из класса А
  32. }
  33. }
Success #stdin #stdout 0.01s 131072KB
stdin
Standard input is empty
stdout
Actor
Bctor
20
20