© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
6 replies
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
  }
}
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Abstract class functions
C#CC# / help
4y ago
❔ abstract class virtual methods vs default implementation interface
C#CC# / help
4y ago
✅ Abstract Class vs Interface
C#CC# / help
10mo ago
✅ Testing an abstract class
C#CC# / help
15mo ago