Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the default constructor access modifer?

Tags:

c#

I am confuse on what is the default constructor access modifier and what does this MSDN statemtn says

 If the direct base class does not have an accessible parameterless instance constructor, a compile-time error occurs.

Because when i applied this with a test program it fails. I can make an object or class that is inheriting another class thogh there is no exteranal parameerless constructor defined.

class A 
{
}
class B : A
{
}
class C
{

    public void main()
    {

        B objB = new B();// as per MSDN here should be the compile time error.

    }
}

[Source]

like image 668
NoviceToDotNet Avatar asked Dec 08 '22 09:12

NoviceToDotNet


1 Answers

If the direct base class does not have an accessible parameterless instance constructor, a compile-time error occurs.

If a constructor is not defined for a class, the compiler will automatically generate a public default constructor.

like image 196
F11 Avatar answered Dec 11 '22 09:12

F11