Great intro. I hit an error on line 11 of the final code. I get an Error:(11, 16) java: Math() has private access in Math. IntelliJ's linter is yelling about it as well. My Java knowledge is minimal so I'm wondering how would I fix this error? I'm guessing it has something to do with line 2 of Math.java.
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.
Great intro. I hit an error on line 11 of the final code. I get an
Error:(11, 16) java: Math() has private access in Math
. IntelliJ's linter is yelling about it as well. My Java knowledge is minimal so I'm wondering how would I fix this error? I'm guessing it has something to do with line 2 ofMath.java
.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!