I have created a class named Times and I have to construct 4 overloaded methods. I just would like some help understanding overloaded methods and at least maybe some help with the first one. I would really appreciate it. Thanks 🙂
- multiply 2 integers and return the (integer) product
- multiply 3 integers and return the (integer) product
- multiply 2 double values and return the (double) product
- multiply 3 double values and return the (double) product
“Overloaded methods” just means the methods would all have the same name (and be in the same class). The parameters need to be different either in number or type, however.
Since the all multiply stuff, “multiply” makes sense as a name.
The first one:
So it returns an integer (an int), is named “multiply”, takes 2 ints as parameters, that gives us:
It returns the product, so the body is:
And then we’re done with that one:
That gives us:
Use the same approach and the same name for the others.