---
title: "Prevent access of default constructor of base class in C#"  
description: "Prevent access of default constructor of base class in C#"  
author: "Anonymous User"  
published: 2014-03-26  
updated: 2019-04-03  
canonical: https://www.mindstick.com/forum/1988/prevent-access-of-default-constructor-of-base-class-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Prevent access of default constructor of base class in C#

I have a [base class](https://www.mindstick.com/blog/116/base-class-initilization) and a [derived class](https://answers.mindstick.com/qa/30686/what-is-a-base-class-and-derived-class). As both the classes are [serializable](https://www.mindstick.com/interview/12756/what-is-difference-between-serializable-and-parcelable-which-is-best-approach-in-android), it require to have [default constructor](https://www.mindstick.com/forum/34531/default-constructor). But I want to prevent access of default constructor of base class because it may cause a [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) [if someone](https://answers.mindstick.com/qa/99016/is-there-any-device-that-can-detect-if-someone-opens-your-backpack) will create object with default constructor. I cannot make it [as private](https://www.mindstick.com/interview/2711/what-if-the-main-method-is-declared-as-private) or [internal](https://www.mindstick.com/interview/773/describe-the-accessibility-modifier-protected-internal) as it is base class. Making it private shows error in derived class. The error is base does not have any [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) less constructor. How can I prevent access of default constructor of base class? Below is the sample code.

```
[Serializable]public class Test1(){    public Test1()   {    }    public Test1(int i, int j)    {    }    public Test1(int i, int j, int k)    {    } }[Serializable]public class Test2():Test1{    public Test2():base()    {    }    public Test2(int i, int j):base(i,j)    {    }    public Test2(int i, int j, int k):base(i,j,k)    {    }}
```

## Replies

### Reply by y?n ph?m

Post is removed by the Admin.

### Reply by rahul kumar

Post is removed by the Admin.

### Reply by Pravesh Singh

Hi Jay,

Use protected .

The protected keyword is a member access modifier. A protected member is accessible within its class and by derived class instances. For a comparison of protected with the other access modifiers.

```
public class Test1(){    protected Test1()    {    }    public Test1(int i, int j)    {    }    public Test1(int i, int j, int k)    {    } }
```


---

Original Source: https://www.mindstick.com/forum/1988/prevent-access-of-default-constructor-of-base-class-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
