In the following example consider you have a solution hosting two projects: ConsoleApplication1 and SampleClassLibrary. The first project will have the classes SampleClass1 and SampleClass2. The second one will have SampleClass3 and SampleClass4. In other words we have two assemblies with two classes each. ConsoleApplication1 has a reference to SampleClassLibrary.
See how SampleClass1.MethodA interacts with other classes and methods.
SampleClass1.vb:
Imports SampleClassLibrary Public Class SampleClass1 Public Sub MethodA() 'MethodA can call any of the following methods because 'they all are in the same scope. MethodB() MethodC() MethodD() MethodE() 'Sample2 is defined as friend. It is accessible within 'the type itself and all namespaces and code within the same assembly. Dim class2 As New SampleClass2() class2.MethodA() 'class2.MethodB() 'SampleClass2.MethodB is not accessible because 'this method is private. SampleClass2.MethodB 'can only be called from SampleClass2.MethodA, 'SampleClass2.MethodC, SampleClass2.MethodD 'and SampleClass2.MethodE class2.MethodC() 'class2.MethodD() 'SampleClass2.MethodD is not accessible because 'this method is protected. SampleClass2.MethodD 'can only be called from any class that inherits 'SampleClass2, SampleClass2.MethodA, SampleClass2.MethodC, 'SampleClass2.MethodD and SampleClass2.MethodE class2.MethodE() Dim class3 As New SampleClass3() 'SampleClass3 resides in other 'assembly and is defined as public. 'It is accessible anywhere. class3.MethodA() 'class3.MethodB() 'SampleClass3.MethodB is not accessible because 'this method is private. SampleClass3.MethodB can 'only be called from SampleClass3.MethodA, 'SampleClass3.MethodC, SampleClass3.MethodD 'and SampleClass3.MethodE 'class3.MethodC() 'SampleClass3.MethodC is not accessible because 'this method is friend and resides in another assembly. 'SampleClass3.MethodC can only be called anywhere from the 'same assembly, SampleClass3.MethodA, SampleClass3.MethodB, 'SampleClass3.MethodD and SampleClass3.MethodE 'class4.MethodD() 'SampleClass3.MethodE is not accessible because 'this method is protected friend. SampleClass3.MethodD 'can only be called from any class that resides inside 'the same assembly and inherits SampleClass3, 'SampleClass3.MethodA, SampleClass3.MethodB, 'SampleClass3.MethodC and SampleClass3.MethodD 'Dim class4 As New SampleClass4() 'SampleClass4 is not accessible because 'it is defined as friend and resides in 'other assembly. End Sub Private Sub MethodB() 'Doing MethodB stuff... End Sub Friend Sub MethodC() 'Doing MethodC stuff... End Sub Protected Sub MethodD() 'Doing MethodD stuff... End Sub Protected Friend Sub MethodE() 'Doing MethodE stuff... End Sub End Class
SampleClass2.vb:
Friend Class SampleClass2 Public Sub MethodA() 'Doing MethodA stuff... End Sub Private Sub MethodB() 'Doing MethodB stuff... End Sub Friend Sub MethodC() 'Doing MethodC stuff... End Sub Protected Sub MethodD() 'Doing MethodD stuff... End Sub Protected Friend Sub MethodE() 'Doing MethodE stuff... End Sub End Class
SampleClass3.vb:
Public Class SampleClass3 Public Sub MethodA() 'Doing MethodA stuff... End Sub Private Sub MethodB() 'Doing MethodB stuff... End Sub Friend Sub MethodC() 'Doing MethodC stuff... End Sub Protected Sub MethodD() 'Doing MethodD stuff... End Sub Protected Friend Sub MethodE() 'Doing MethodE stuff... End Sub End Class
SampleClass4.vb:
Friend Class SampleClass4 Public Sub MethodA() 'Doing MethodA stuff... End Sub Private Sub MethodB() 'Doing MethodB stuff... End Sub Friend Sub MethodC() 'Doing MethodC stuff... End Sub Protected Sub MethodD() 'Doing MethodD stuff... End Sub Protected Friend Sub MethodE() 'Doing MethodE stuff... End Sub End Class