I have a class with the constructor:
...
Date d1;
Date d2;
public DateClass(Date d1, Date d2) {
this.d1 = d1;
this.d2 = d2;
}
...
Then in another class I want to use this constructor:
...
DateClass d = new DateClass(what I should I write here to create Date in format mm-dd-yyyy);
System.out.println(d);
...
Thank you!
P.S This in not a part of a homework. I really do not know how to do it.
You can make a new
Dateby calling the constructor.This is the simplest way, and will certainly work; however, as Carlos Heuberger correctly notes, this is deprecated, meaning that other ways are preferred. You can also make a new
DatethroughDateFormat:To be able to print in
mm-dd-yyyyformat, implementtoString: