VB.Net Access Levels

241 Views Asked by At

I am currently working on a VB.Net project and came across something that befuddled me a little bit. So I essentially have the following code structure:

Public Class MainClass

    Private Class HiddenClass
    End Class

    Private Class ChildA
        Inherits From HiddenClass
    End Class

    Private Class ChildB
        Inherits From HiddenClass
    End Class

End Class

Public Class BuildingBlock

    Protected lbl As Label
    Protected btn As Button
    Protected main As New MainClass()

End Class

Now I am getting an error from setting main as Protected. Specifically the error I get is:

'main' cannot expose type 'MainClass' outside the project through class 'BuildingBlock'

Now I Googled the error, and found the solution was to:

Change the access level of the variable, procedure parameter, or function return to be at least as restrictive as the access level of its data type.

So, I changed it to Public, and everything was perfectly fine. But just to test thing, I changed to access to Private, Friend, and Protected Friend. Protected Friend still had the error as I was expecting, but both Private and Friend did not, even though they are different access levels than that of the data type.

So I am wondering why I would only get this error for listing this object as Protected, and not at any other level of access.

0

There are 0 best solutions below