The 2 guys above have already answered this and quite well I must add; but just in case (let me know if this is not needed lol
)
In your actual progam (the one with the main method); you've instantiated a date object from your date class
with the statement:
[B]Date theDate = new Date(8,27,2010);[/B]
Ok, so far so good.
With your next line of code you've written:
[B]theDate.displayDate();[/B]
Now, let's disect this a bit. On the new 'Date' object that you've just instantiated with the previous statement (called theDate as you know) you've invoked the 'displayDate' method. Let's go back to the method that you've written in your Date class and see what it does:
[B]public int displayDate(){
System.out.println("Today's date is" +month+ "/" +day+ "/" +year+".");
return displayDate();
}[/B]
Right then, first off the method makes a call to a the static 'println' method whose job it is to get text on the screen. It does this perfectly by the looks of things, but the problem arises next. After 'printing out' the information, control passes to the next line of code ( return displayDate(); ) Logically speaking this will 'return' to the caller of the original method (which in this case is your program) the result of the method specified (which is displatDate(); ).
The issue though is that you already within the display date method. So what you are in fact saying to the compiler is the following:
Do the 'displayDate' method
{* Inside the method
Now print the following (" ")
return the value of the 'displayDate' method
*oops we're already in that method, go back to the top then.
}
Control will thus go back to the top with the last statement, flow down until it reaches the return and then go back to the top again. We've got an infinite loop on our hands!
-------------------------------------------------------------------------------------------------------------------------------------
The solution is to have only one of your two options. Either a println method that will give you the data in question, or have the method return you the date in full on it's own (& not return the value of a method itself)