Wednesday 27 July 2016

C Sharp Visibility Mode Tutorial

C# Visibility Mode Program

class test
    {
         int a;
        protected int b;
        public test(int a,int b)
        {
            this.a = a;
            this.b = b;
        }
        public test()
        {

            a = b = 0;
        }
        public void display()
        {
            Console.WriteLine(a + "\n" + b);
        }
    }
    class best : test
    {
        int c;
        public best() : base(10,20)
        {
            c = 100;
        }
        public void display()
        {
            Console.WriteLine("\nClass best c={0}\nClass test B={1}\n", c, b);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            best ob = new best();
            ob.display();
            // ob.b; won't run because b is private and accessible only in best or test class body
        }
    }
Next Topic

No comments:

Post a Comment