C#C
C#3y ago
popcorn

✅ abstract class - default value

Hello, I have a simple code:
public abstract class Vehicle 
{
  public int speed = 1;

  public void PrintSpeed() 
  {
    Console.WriteLine(speed);
  }
}

public class Car : Vehicle 
{
  public int speed = 9;

  public void DoSomething() 
  {
    // ....
    PrintSpeed(); // Here it prints 1, but I want it to print 9
  }
}


Is it possible to have an abstract class hold default parameter but when I override that then when I call the function it will use the overridden parameter in the child class?
Was this page helpful?