15.类的修饰符

1. 类内部

namespace _15.类的修饰符
{
    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.  程序集内(public,internal,Protected interal可以通过)

namespace _15.类的修饰符
{
    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.  子类(public, internal, protected, Protected internal 可通过)

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. 程序集外(public可通过)

 

 


posted @ 2010-03-06 20:35  平凡人生  阅读(220)  评论(0编辑  收藏  举报