Is a C# class without constructor possible?

(Last Updated On: March 23, 2018)

Answer: Yes, C# class without constructor is possible. In fact, we can have a class without any constructor in C#. If we don’t declare any constructors in a class, the compiler automatically provides a public parameter less constructor. And it is ok to instantiate c# class without constructor.

In below C# code example program, we don’t have any constructor in the class Person.



Abstract class without constructor in C#

Compiler provides protected parameterless constructor for an abstract class C# program. We know that in an inheritance hierarchy, if we create an object of a child class, first base class and then child class constructor will be called. You may wish to read C# constructor and destructor call order.

Hence, if base class does not contains any constructor, compiler provides protect parameter less constructor.

In below C# program example class Person is an abstract class and an Employee class has been derived from it. If we created the object of the child class Employee, first base class default protected constructor then derived class constructor will be called.


[If you want to get an idea about abstract class  read this interview questions on C# abstract class that is  what feature to use to have common behaviors in one class and force other classes to implement others behaviours.]





Derived Class Employee constructor
Base class:getPersonProfile() method – have no constructor