Thursday, May 7, 2009

Working with OverRiding

  • OverRiding is a concept of having two methods with same name and same args in base and derived classes.
  • In OverRiding,by default importance will be given to local methods.
  • "base" is a Keyword.
  • "base" points to parent class.
  • "this" points to current class.
  • In OverRiding,in order to access parent class methods,base.methodname() need to be used
  • "base" keyword can be used with methods,fields and constructors also
Example on "base" keyword with methods.

              class A
        {
            public void Show()
            {
                MessageBox.Show("From A....");

            }
        }
        class B : A
        {
            public void Show()
            {
                MessageBox.Show("From B....");
                base.Show();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            B obj = new B();
            obj.Show();
        }

No comments:

Post a Comment