這是一個家庭作業。 我必須執行以下操作:如何在Java中創建對象時執行日期?
私有日期日期創建哪個存儲,何時創建對象。
private Date dateCreated;
getter方法for dateCreated。
public Date getDateCreated() {
return dateCreated;
}
而且必須實現此方法主要:
public static void main(String[] args){
Account a=new Account(1122,20000,4.5);
a.withdraw(2500);
a.deposit(3000);
System.out.println(a.getBalance());
System.out.println(a.getMonthlyInterestRate()+"%");
System.out.println(a.getDateCreated()); // or another method what can get
//time when the object created
}
我已經試過了getTime(),但我不知道我怎麼可以在我的代碼中使用。 我看到了一些解決方案,但它總是爲此創建另一個類。 我想要一個簡單的解決方案。 (說不定什麼時候申報dateCreated會現場)
這需要澄清 – jayunit100
謝謝大家的答案! – blaces