O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.7. Method overloading

There isn't much difference between method overloading in Java and in C#. You have multiple methods of the same name and return type in the same class.

Like Java

  • You cannot consider two methods with the same name and parameters but with a different return type as method overloading. For example, having

    public void DoThis (int j) {}
    

    and

    public int DoThis (int j) {return 0;}
    

    in the same class is illegal.

  • Constructors can be similarly overloaded. Like Java, you can invoke overloaded constructors from another constructor using the this keyword (see section 7.6).

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required