1.Class
Namespace _ 15. Class Modifier
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
DefaultMethod ();
PublicMethod ();
PrivateMethod ();
InternalMethod ();
ProtectedMethod ();
ProtectedInternalMethod ();
}
Void defaultMethod ()
{
MessageBox. Show ("This is defaut method ");
}
Public void publicMethod ()
{
MessageBox. Show ("This is public method ");
}
Private void privateMethod ()
{
MessageBox. Show ("This is private method ");
}
Internal void internalMethod ()
{
MessageBox. Show ("This is internal method ");
}
Protected void protectedMethod ()
{
MessageBox. Show ("This is protected method ");
}
Protected internal void protectedInternalMethod ()
{
MessageBox. Show ("This is protectedInternal method ");
}
}
}
2.In the Assembly (Public, internal, Protected interal can be passed)
Namespace _ 15. Class Modifier
{
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
Mod mod = new Mod ();
// Mod. defaultMethod ();
Mod. publicMethod ();
// Mod. privateMethod ();
Mod. internalMethod ();
// Mod. protectedMethod ();
Mod. protectedInternalMethod ();
}
}
Class Mod
{
Void defaultMethod ()
{
MessageBox. Show ("This is defaut method ");
}
Public void publicMethod ()
{
MessageBox. Show ("This is public method ");
}
Private void privateMethod ()
{
MessageBox. Show ("This is private method ");
}
Internal void internalMethod ()
{
MessageBox. Show ("This is internal method ");
}
Protected void protectedMethod ()
{
MessageBox. Show ("This is protected method ");
}
Protected internal void protectedInternalMethod ()
{
MessageBox. Show ("This is protectedInternal method ");
}
}
}
3.Subclass (public, internal, protected, Protected internal available)
Public partial class Form1: Form
{
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
Test test = new Test ();
Test. Run ();
}
}
Class Test: Mod
{
Public void Run ()
{
// DefaultMethod ();
PublicMethod ();
// PrivateMethod ();
InternalMethod ();
ProtectedMethod ();
ProtectedInternalMethod ();
}
}
Class Mod
{
Void defaultMethod ()
{
MessageBox. Show ("This is defaut method ");
}
Public void publicMethod ()
{
MessageBox. Show ("This is public method ");
}
Private void privateMethod ()
{
MessageBox. Show ("This is private method ");
}
Internal void internalMethod ()
{
MessageBox. Show ("This is internal method ");
}
Protected void protectedMethod ()
{
MessageBox. Show ("This is protected method ");
}
Protected internal void protectedInternalMethod ()
{
MessageBox. Show ("This is protectedInternal method ");
}
}
4.Outside the Assembly (public can be passed)