Anyone an access modifier guru?

Javin007

New member
Joined
Mar 30, 2012
Messages
1
Programming Experience
10+
So here's what I'm trying to do:

VB.NET:
Public Class Foo

   Public Class Bar
      XXXXX Meh As Boolean
   End Class

   Private Sub Yar()
      Dim n As New Bar
      n.Meh = True          'This should work as expected.
   End Sub

End Class



Public Class Main

   Private Sub Yar()
      Dim n As New Bar
      n.Meh = True          'This should throw an error saying that the "Meh" isn't accessible.
   End Sub

End Class

Hopefully this makes sense.

The idea is that .Meh SHOULD be visible within the "Foo" class, but NOT within the "Main" class. So the second call of n.Meh = True should throw an error, while the first one would be fine.

Is this kind of encapsulation even possible?

-Javin
 
It is only possible if you make Bar class Private (and Meh method Public).
In a library Friend can be used to allow access within library, but not outside.
 
Back
Top