code_junkie

Virtualization in Super Class Constructor

Nov 12th, 2011
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. using System;
  2. namespace Problem
  3. {
  4. public class BaseClass
  5. {
  6. public BaseClass()
  7. {
  8. Console.WriteLine("Hello, World!");
  9. this.PrintRandom();
  10. }
  11. public virtual void PrintRandom()
  12. {
  13. Console.WriteLine("0");
  14. }
  15. }
  16.  
  17. public class Descendent : BaseClass
  18. {
  19. private Random randomValue;
  20. public Descendent()
  21. {
  22. Console.WriteLine("Bonjour, Monde!");
  23. randomValue = new Random();
  24. }
  25. public override void PrintRandom()
  26. {
  27. Console.WriteLine(randomValue.NextDouble().ToString());
  28. }
  29.  
  30. public static void Main()
  31. {
  32. Descendent obj = new Descendent();
  33. obj.PrintRandom();
  34. Console.ReadLine();
  35. }
  36. }
  37. }
Add Comment
Please, Sign In to add comment