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).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.176.194