pavansagar
Member
- Joined
- Jan 11, 2006
- Messages
- 8
- Programming Experience
- Beginner
To my knowledge, Friend is accessible throughout the project and protected is accessible in the base class and all its derived classes. So protected friend means it should be accessible throughout the project and in the base class and in all derived classes (these may be in any other project).
Here I created classlibrary of name classlibrary1 and it contains the following code.
Public Class base1
Friend a As Integer = 1
Protected b As Integer = 2
Protected Friend c As Integer = 3
Protected Friend Overridable Sub display() 'error here
Console.WriteLine("protected friend--in base1 class in another project")
End Sub
End Class
Now I compiled it and imported this classlibrary1.dll into my current project by adding reference. In this the, method display () which is declared as protected friend is overridden. But it is showing the error as “protected overrides sub display () cannot override protected overridable sub display () because they have different access levels.” But 'c' isalso a variable which is declared as 'protected friend'. It is accessible in the current project..so why I am not able to access the display() method in the current project.
This is the code which I given in the current project.
Imports ClassLibrary1
Public Class firstderived
Inherits base1
Protected Friend Overrides Sub display()
Console.WriteLine("protected friend--in first derived class ")
End Sub
End Class
Module Module1
Sub Main()
Dim obj1 As base1 = New base1
Dim obj2 As New firstderived
obj1.display() 'errror here
obj2.display()
End Sub
End Module
Here I created classlibrary of name classlibrary1 and it contains the following code.
Public Class base1
Friend a As Integer = 1
Protected b As Integer = 2
Protected Friend c As Integer = 3
Protected Friend Overridable Sub display() 'error here
Console.WriteLine("protected friend--in base1 class in another project")
End Sub
End Class
Now I compiled it and imported this classlibrary1.dll into my current project by adding reference. In this the, method display () which is declared as protected friend is overridden. But it is showing the error as “protected overrides sub display () cannot override protected overridable sub display () because they have different access levels.” But 'c' isalso a variable which is declared as 'protected friend'. It is accessible in the current project..so why I am not able to access the display() method in the current project.
This is the code which I given in the current project.
Imports ClassLibrary1
Public Class firstderived
Inherits base1
Protected Friend Overrides Sub display()
Console.WriteLine("protected friend--in first derived class ")
End Sub
End Class
Module Module1
Sub Main()
Dim obj1 As base1 = New base1
Dim obj2 As New firstderived
obj1.display() 'errror here
obj2.display()
End Sub
End Module