fork download
  1. using System;
  2.  
  3. enum Models {FIVE, SIX, SEVEN, NINE}
  4.  
  5. class Cars {
  6. public int wheels = 4;
  7. private float speed;
  8. protected bool isWorking = true;
  9.  
  10. public Models model;
  11.  
  12. public void SetValues(float speed, bool isWorking) {
  13. this.speed = speed;
  14. this.isWorking = isWorking;
  15. }
  16. public virtual void GetValues() {
  17. Console.WriteLine ("Car speed is: " + this.speed + " " +
  18. "Is working: " + this.isWorking);
  19. }
  20.  
  21. public Cars (int wheels, float speed, bool isWorking) {
  22. this.wheels = wheels;
  23. this.speed = speed;
  24. this.isWorking = isWorking;
  25.  
  26. }
  27.  
  28. public Cars () {}
  29. }
  30.  
  31. class Trucks : Cars {
  32. public int passeng;
  33.  
  34. public Trucks(int wheels, float speed, bool isWorking, int passeng) : base(wheels, speed, isWorking) {
  35. this.passeng = passeng;
  36. }
  37.  
  38. public override void GetValues () {
  39. base.GetValues ();
  40. Console.WriteLine ("Passengers: " + this.passeng);
  41. }
  42. }
  43.  
  44. public class Test
  45. {
  46. public static void Main()
  47. {
  48. Trucks man = new Trucks(8, 150.087f, true, 2);
  49. man.GetValues();
  50. // Console.WriteLine (man.passeng);
  51.  
  52. Cars Five = new Cars (4, 120.07f, true);
  53. Five.model = Models.FIVE;
  54. // Console.WriteLine (Five.wheels);
  55. // Five.SetValues(120.07f, true);
  56. Five.GetValues();
  57.  
  58.  
  59.  
  60. Cars Nine = new Cars ();
  61. Nine.model = Models.NINE;
  62. Nine.wheels = 6;
  63. Console.WriteLine (Nine.wheels);
  64. Nine.SetValues(60.00f, false);
  65. Nine.GetValues();
  66. }
  67. }
Success #stdin #stdout 0.02s 16352KB
stdin
Standard input is empty
stdout
Car speed is: 150.087 Is working: True
Passengers: 2
Car speed is: 120.07 Is working: True
6
Car speed is: 60 Is working: False