Keep in mind! When you call date.toString();
you aren't converting the entire date
variable into a String
; since that doesn't actually change anything in the object, that line does nothing.
Fortunately it still works since when you call println(date)
with the PrintStream
object System.out
, you are actually calling the variation of println()
that takes an Object
as a parameter instead of the one that takes a String
, and what that does is get the result of the parameter's toString()
method and prints that. So, it's the exact same result in the end.
The real problem is in your constructor method. Look really closely, and read through it. Pretend you are the parameter theYear
and your value is 2222. At what point are you going to be used, and how?
spoilers below, seriously go look
You are in fact never setting the field myYear
to anything unless the parameter theYear
is invalid! The best solution here would be to add that missing else
clause after you check theYear
to match up with your handling of the rest of the parameters.