Answer the question
In order to leave comments, you need to log in
Why do abstract classes need constructors?
Hello everyone!
I came across this code
abstract class AbstractClass
{
public AbstractClass()
{
...
}
}
Answer the question
In order to leave comments, you need to log in
So that in each constructor of the heir, do not write the same thing.
If some other class is inherited from an abstract class, then why not specify the fields and methods of the abstract class without using a constructor?
Like this
abstract class AbstractClass
{
public int field = 1;
public void Method();
}
class ConcreteClass : AbstractClass
{
public ConcreteClass()
{
public override void Method()
{
Console.WriteLine("Реализация");
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question