List All Class Access Specifiers?

 Posted by Pardhu2020 on 2/18/2014 | Category: C# Interview questions | Views: 2135 | Points: 40
Answer:

There are five access specifiers in Visual Basic .NET defined as follows:

Public – Applied at the class level and is the most common specifier. Public Classes are classes that are intended to be used by any consumer.
Public Class PubClass
End Class

Protected – can only be applied to Nested Classes. Are only accessible within the class and within the child classes.
Public Class HasProtected
Protected Class ProtectedClass
End Class
End Class

Friend – Are accessible only within the program in which they are defined. If you add the Friend access specifier to a class definition, instance of that class can only be created from within th same program.
Friend Class FriendClass
Public Shared Sub PublicMethod()
MsgBox(“FriendClass.PublicMethod”)
End Sub
End Class

Protected Friend – Represents a union of the Protected and Friend Specifiers. Protected class must be nested class, thus Protected Friend class must be nested too.
Public Class HasProtectedFriend
Protected Friend Class ProtectedFriend
Public Shared Sub Test()
MsgBox(“test”)
End Sub
End Class
End Class

Private – Can only be applied to a nested class. A Private nested class represents implementation details of the class. When you have complex problem that requires more problem solving horsepower then simple methods can provided, defining a nested private class that implements the abstraction.
Public Class HasPrivate
Private Class PrivateClass
End Class
End Class


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response