I\'m a newbie in java. I\'m writing a class where the constructor must check the price parameter and ensure it is not a negative number. And if it is negative, it must set
Your getting infinite recursion, because your if
condition checks your getprice()
method, not your price
variable.
Many modern compilers will warn you when you have coded something that results in infinite recursion.
I still sometimes come across this error too, especially with IDE's that have intellisense.
Good luck learning Java! :)