publicfinalclassMath{publicstaticintadd(intfirstNumber,intsecondNumber){returnfirstNumber+secondNumber;}publicstaticintmultiply(intmultiplicand,intmultiplier){returnmultiplicand*multiplier;}publicstaticdoubledivide(intdividend,intdivisor){if(divisor==0)thrownewIllegalArgumentException("Cannot divide by zero (0).");returndividend/divisor;}}
In case you or someone else also wonders why, the private Math() {} refers to the constructor of our Math class, I made it private at the beginning because all it's methods are static, which prevents anyone from trying to instantiate it. But later on I decided to also add an example where we had the need to use an object and I forgot to update it hahaha.
Thanks for letting me know, Seth!
That's my fault.
Try removing this from the Math.java file:
The entire class should be like this now:
In case you or someone else also wonders why, the
private Math() {}
refers to the constructor of our Math class, I made itprivate
at the beginning because all it's methods arestatic
, which prevents anyone from trying to instantiate it. But later on I decided to also add an example where we had the need to use an object and I forgot to update it hahaha.That works. Thanks!