0

I'm calling to a method, from a method And I have this code:

public int ValidateInfo ()
{
return
     this.day = 1;
	 this.month = 1;
	 this.year =1900;
	
}

However, on the 'Month' line, it is saying that I need to delete it,
Why is this?

Edited by iraqi4life: n/a

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Zhoot
0

Are you trying to return all three values in that method? If that is the case, it is not possible. And why are you setting the values to 1 that your are returning? Please explain a little more what you are doing or give some more code.

If you want to return all three values from that method you need to encapsulate them into an object.

It looks like you should make a Date object with day, month, and year as member variables. Then you can return the Date object from that method instead.

The code you have written there will not compile. You can only return 1 object.

0

Just a supplement to SasseMan's post.

Given the code you provided, JAVA will see that the lines after the return statement, "return this.day = 1;", as waste and therefore it wants you to delete them, hence you get the error message you provided.

To resolve this; Follow SasseMan's advice about making them into a date object (if you want to return an actual date), or make the method into a void method, which does not require a return.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.