C
C
CityzenUNDEAD2020-08-05 10:38:58
C++ / C#
CityzenUNDEAD, 2020-08-05 10:38:58

Why do abstract classes need constructors?

Hello everyone!
I came across this code

abstract class AbstractClass 
    { 
        public AbstractClass() 
        {
            ...
        }

    }

The code is, of course, conditional. The main question is, what for an abstract class constructor? I still don’t know c# well, but it’s impossible to instantiate such classes like them. Maybe this is nonsense, who wrote it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2020-08-05
@CityzenUNDEAD

So that in each constructor of the heir, do not write the same thing.

C
CityzenUNDEAD, 2020-08-05
@CityzenUNDEAD

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 question

Ask a Question

731 491 924 answers to any question