0
I am studying access modifiers in Vb.net and I came up with a question in Protected Friend
According to the website macoratti.net:
Protected: hides members of a class and "members marked with the Protected modifier can be accessed in the same class and in all classes they inherit from the class."
Friend: "you want all classes in your project to be able to access members of your class but classes outside of your project do not have this right.
Neither the modifier in this scenario Private
nor the Protected
can help you, for this situation we have the modifier Friend
.
Therefore, I have two projects in the same solution, Proj1
and Proj2
:
In Proj1
, have the class Student:
Public Class Aluno
Public Nome As String
Protected Endereco As AlunoEndereco
Protected Friend idade As Integer
Protected Class AlunoEndereco
Public Rua As String
Public Cidade As String
Public Estado As String
Public Cep As String
End Class
End Class
and in Proj2
I have the Test class I inherit from Student:
Class Teste
Inherits Aluno
Sub New()
idade = 2
End Sub
End Class
As an access modifier Protected
allows a member to be visible only in class and inherited classes, but when combining with the modifier protected
with friend
, I thought it would happen that the age camp could only be seen within the class at Proj1
but not in Proj2
, but it also happened that it was possible to access age from the Test class in Proj2
, could someone explain to me why this happens?
Some doubt is still vague...?
– novic
okay, all right.
– Vinicius V