我是新來的java,並且很難理解我在這裏做錯了什麼。我仍然很難完全理解抽象類和接口,所以我認爲這就是我的問題來自何處。試圖將GregorianDate傳遞給Java中的構造函數
我想創建一個類,將允許我創建黨的對象,我能夠實例化除日期以外的所有變量。以下是我迄今爲止:
public class Main {
public static void main(String[] args) {
...
Party joes = new Party("Joes party", "Joe", "Joe's Place",
new GregorianCalendar(2012,10,10));
joes.printParty();
}
}
public class Party {
//attributes of party
private String partyName;
private String partyHost;
private String location;
private GregorianCalendar partyTime;
public Party(String partyName, String partyHost, String location, GregorianCalendar partyTime){
this.partyName = partyName;
this.partyHost = partyHost;
this.location = location;
this.partyTime = partyTime;
}
}
當我打印出來,我得到:
"Joes party is going to be hosted by Joe at Joe's Place on:
java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=false,lenient=true..."
請參閱http://stackoverflow.com/questions/30434334/gregoriancalendar-outputs-the-date-is-java-util-gregoriancalendimeime-11415564 – Tunaki
對不起,如果我失去了一些東西,但我看到了這個答案,我想這是一個輸出問題。我認爲我的數據傳遞方式存在問題。 – Kronos
你爲什麼這麼想? – Tunaki