Product Method Overloading

后端 未结 2 1636
花落未央
花落未央 2021-01-23 23:01

so I was working on this problem on CodeHS, then I was stuck for so long so decided to ask here.

The exercise is to overload the product method to allow for multiplying

2条回答
  •  难免孤独
    2021-01-23 23:41

    be aware that overloading means, the name of the method and the return type remains the same as the original/ initial method.

    then you need to define/ implement those methods>

    2 doubles would be:

    public int product(double one, double two)
    {
        return (int)(one * two);
    }
    

    an int and a double would be

    public int product(int one, double two)
    {
        return (int)(one * two);
    }
    

    etc

提交回复
热议问题