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?

Recommended Answers

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.