Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 28th, 2012  |  syntax: None  |  size: 1.48 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. C# abstract classes inheritance
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace A_work_2
  8. {
  9. public abstract class Vehicle
  10. {
  11.     public string vehicleName;
  12.     public abstract void Display();
  13.  
  14. }
  15. }
  16.        
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21.  
  22. namespace A_work_2
  23. {
  24. public class Vehicle4Wheels : Vehicle
  25. {
  26.     public override void Display()
  27.     {
  28.         Console.WriteLine("Car with four wheels.");
  29.     }
  30. }
  31. }
  32.        
  33. using System;
  34. using System.Collections.Generic;
  35. using System.Linq;
  36. using System.Text;
  37.  
  38. namespace A_work_2
  39. {
  40. public class SportCar : Vehicle4Wheels {
  41.     public override void Display()
  42.     {
  43.         Console.WriteLine("Sport version of the car.");
  44.     }
  45. }
  46. }
  47.        
  48. using System;
  49. using System.Collections.Generic;
  50. using System.Linq;
  51. using System.Text;
  52.  
  53. namespace A_work_2
  54. {
  55. public class Rally : SportCar
  56. {
  57. private double motorPower = 408;
  58. private double carWeight = 2380;
  59. private double carAcceleration = 4.7;
  60. private double highestSpeed = 250;
  61.  
  62. public double SpecificPower()
  63. {
  64.     double specificPower = motorPower / carWeight;
  65.     return specificPower;
  66. }
  67.  
  68. public override void Display()
  69. {
  70.  
  71.    Console.WriteLine("The acceleration is: {0}.nThe highest speed is {1} km/h.", carAcceleration, highestSpeed);
  72.    Console.WriteLine("Specific power is {0}", SpecificPower());
  73.  
  74.  
  75. }
  76. }
  77. }
  78.        
  79. private double carWeight;
  80.        
  81. Vehicle sportCar = new SportCar();
  82. sportCar.Display();
  83.  
  84. Vehicle rally = new Rally();
  85. rally.Display();