title: C# abstract classes inheritance
body: <p>hej guys,</p>
  
  <p>I am trying to solve this homework. I have reached a dead end and I am looking for someone who could help with this issue.</p>
  
  <p>This is the task I am trying to solve:</p>
  
  <blockquote>
    <p>Work 2: An abstract class is not a complete class, it misses some
    parts, and you cannot create     objects from it. The programmer who
    writes the derived classes must fill in the missing    parts. Consider
    an abstract class Vehicle. Derive two hierarchies from this class as
    it  is shown below: Now, write 4 classes, see the yellow rectangle.
    Start from the abstract  base class Vehicle -> Vehicle with 4 wheels
    -> Sport Cars and stop at the derived class          Rally, which is the most specific class. The class Vehicle contains a field which
    holds   the vehicle name and an abstract method void Display().</p>
    
    <p>Implement this function in the derived classes, so that the function
    returns  information about the vehicle, e.g. the motor power and other
    necessary properties. The  last derived class has private fields to
    hold the motor power, the car weight, the car  acceleration, the
    highest speed and a function that computes the specific power (power 
    / weight). The function Display returns a text string with all this
    information. Test  your work in a Console application that uses
    objects of the type of the classes Sport  car and Rally.</p>
  </blockquote>
  
  <p>Class Vehicle:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace A_work_2
  {
  public abstract class Vehicle
  {
      public string vehicleName;
      public abstract void Display();
  
  }
  }
  </code></pre>
  
  <p>Class Vehicle4Wheels:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace A_work_2
  {
  public class Vehicle4Wheels : Vehicle
  {
      public override void Display() 
      {
          Console.WriteLine("Car with four wheels.");
      }
  }
  }
  </code></pre>
  
  <p>Class SportCar:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace A_work_2
  {
  public class SportCar : Vehicle4Wheels {
      public override void Display()
      {
          Console.WriteLine("Sport version of the car.");
      }
  }
  }
  </code></pre>
  
  <p>Class Rally:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace A_work_2
  {
  public class Rally : SportCar
  {
  private double motorPower = 408;
  private double carWeight = 2380;
  private double carAcceleration = 4.7;
  private double highestSpeed = 250;
  
  public double SpecificPower()
  {
      double specificPower = motorPower / carWeight;
      return specificPower;
  }
  
  public override void Display()
  {
  
     Console.WriteLine("The acceleration is: {0}.\nThe highest speed is {1} km/h.", carAcceleration, highestSpeed);
     Console.WriteLine("Specific power is {0}", SpecificPower());
  
  
  }
  }
  }
  </code></pre>
  
  <p>I am not sure if I understand the task clearly and with the code I have so far, I dont know if I am on the right way to make it happen. I dont understand abstract classes and inhertiance very much.</p>
  
  <p>Thank you for your help!</p>
  
  <p>V.</p>
  
  <p>EDIT: My question is: How can I change the code I have written to fulfill the task I have been given? Because I am not sure how to be general while writing the code. When I add car attribute to the Vehicle4Wheels class like:</p>
  
  <pre><code>private double carWeight;
  </code></pre>
  
  <p>How can I then approach this attribute in later derived classes?</p>