• Startseite
  • Tutorials
  • Kontakt
  • Mein Account
Panjutorials
  • Startseite
  • Tutorials
  • Kontakt
  • Mein Account

overload functions of super classes

You can override the functions of superclasses in programming not only with the same parameters, but you can also use different ones. This may be useful when, e.g. In general the functionality of the superclass should be used however some functions should do different things.

Let’s look at how to do this in CSharp. For this I build on the code of the last article.

  class Programm
    {


        public static void Main(string[] args)
        {
            Audi A4 = new Audi();
            BMW M5 = new BMW();

            A4.repair();
            A4.repair("A4");
            M5.repair();
            Console.ReadLine();
        }


    }

    class Car
    {
        public void repair()
        {
            Console.WriteLine("The car was repaired!");         
        }
    }

    class Audi : Car
    {
        public void repair(string model)
        {
            Console.WriteLine("The Audi " + model + " was repaired!");
        }
    }

    class BMW : Auto
    {

    }

You can see that we can use “overloading” to overwrite a function and give it our desired functionality.
Similar to simply overwriting the functions, overloading often makes even more sense to use. That is if you want to replace the functionality of the superclass (e.g. Superclasses you haven’t written yourself) with your own.