user285372
user285372

Reputation:

Understanding default access modifiers

I am confused about access modifiers, so I thought I would ask a couple of quick questions for clarification:

Is it always the case that in the absence of access modifiers for data members of a class, the default is private, though the class itself is internal?

class A
{
    int x;
}

So, int x is private int x and class A is internal class A?

=========================================

Also, why would the following code not compile?

class A
{
    protected int x;
}

public class B : A
{}

Upvotes: 0

Views: 50

Answers (1)

Sami Kuhmonen
Sami Kuhmonen

Reputation: 31193

As the documentation states, classes and structs are by default internal and their members are private.

The code won't compile because, as the error message will state, you cannot inherit from a less accessible class. In this case the child class would be public and the parent internal.

Upvotes: 1

Related Questions