Hi, Can anybody help me to how we can use base class constructor/methods in deriverd class without creating an instance of base class.

 public class abc
        {
            public abc()
            {
            }
            public void aa()
            {
                MessageBox.Show("base");
            }
            public static string aabb()
            {
                MessageBox.Show("base1");
            }
        }
        public class bcd : abc
        {
          //use above methods
        }

Edited 3 Years Ago by Dani: Formatting fixed

here i doing like this,

public class abc
        {
            public abc(int bb)
            {
                bb = 10;
            }
            public static int  aa(int a)
            {      
         
                MessageBox.Show(a);
            }        
         
        }
        public class bcd : abc
        {
            public bcd (int bb)
            {
                base(bb);
            }
        }

The constructor of your derived class, should call the constructor like:

public bcd(int bb) : base(bb)
{
}

You can normally call a base class' methods as if they were the derived class' methods. However, if you override or hide a base class' method, you can call it like:

base.AMethod()

.

Yep, as nmaillet showed. You have two option, or to access to class`s constructor (his 1st upper example), or to access any of your methods in your base class (his 2nd example).

This article has been dead for over six months. Start a new discussion instead.