0
我被要求實施一個名爲「CarHire」類,它已經包含下面的代碼我如何調用Java中的方法從一類到另一個
public static List<Customer> loadCustomers() {
List<Customer> customers = null;
System.out.println("loadCustomers");
return customers;
}
我的其他類TEXTCustomerDAO包含的方法方法
public void loadCustomers(){
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("customers.txt"));
while ((sCurrentLine = br.readLine()) != null) {
System.out.println(sCurrentLine);
}
} catch (IOException e) {
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
}
}
我該如何調用CarHire類中的loadCustomer方法?
我知道它的簡單只是難以集中精力爲UNI是目前地獄般所以輕度腦屁發生
'CarHire.loadCustomers()',但它會返回'null'。 –
'CarHire'中的方法是靜態的,因此不能被覆蓋。當然你希望它是靜態的?請注意,會有'super.loadCustomers()'在子類中調用超類方法。還要注意,你不能在子類實例上調用一個超類方法,因爲這會破壞多態性(如果你重寫了一個你想重寫的方法,而不是讓調用者決定是否要調用這個方法)。 – Thomas
這裏什麼類是抽象的? – FredK