Start New Discussion within our Software Development Community

Hello everyone. I don't know how to call a method from abstract class in protected method. I know that to call method of some class I need to create an object, then object.Method. What are the other ways to call methods?

Here is the example code:

static public List<Figure> list = new List<Figure>();
public abstract class Figure
{
   public void ReDraw()
        {
            foreach (Figure row in list)
            {

                if (typeof(Circle) == row.GetType())
                {
                    Circle tmp = row as Circle;
                    tmp.Draw(pictureBox1, tmp.mypen, tmp.pos, tmp.num, tmp.size);
                }

                else if (typeof(RightFigure) == row.GetType())
                {
                    RightFigure tmp = row as RightFigure;
                    tmp.Draw(pictureBox1, tmp.mypen, tmp.pos, tmp.num);
                }

                else if (typeof(Triangle) == row.GetType())
                {
                    Triangle tmp = row as Triangle;
                    tmp.Draw(pictureBox1, tmp.mypen);
                }
            }
        }
}

protected override void OnKeyDown(KeyEventArgs e)
{
  if(button1)
  {// call here Method ReDraw(); How to call it?}
  else if(button2)
  {//call here Method ReDraw(); How to call it? }
}

Problem is that class is abstract.
Thank you for your help. :cool:

I don't know how to call a method from abstract class in protected method.

Unless the method is static you don't call it. That's the idea: abstract classes cannot be instantiated and must be inherited from to be used in any useful manner.

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