The public keyword is an access
modifier for types and type members. Public access is the most permissive
access level.
There are no restrictions on accessing
public members.
Uses & Accessibility
1. Can be accessed by objects of the class
2. Can be accessed by derived classes
Example: In the following example display
method and property is direct access.
using System;
namespace Modifier
{
class PublicModifier
{
//public
memebers of class,we can access anywhere
public string FirstName { get; set;
}
public string LastName { get; set;
}
public void
Display()
{
Console.WriteLine("Public method is
accessible outside class");
}
}
public class
Program
{
public static void
Main()
{
PublicModifier obj = new PublicModifier();
//access
to public member of PublicModifier class
obj.Display();
obj.FirstName = "abc";
Console.ReadLine();
}
}
}
Output is:-
No comments:
Post a Comment