比如说我有以下课程:
class SuperModel
{
private OracleProvider database;
private SqlTemplates template;
public SuperModel()
{
this.database = new OracleProvider();
this.template = new SqlTemplates(database);
}
protected SqlTemplates getTemplate()
{
return this.template;
}
}
现在我有以下课程扩展上述内容:
class Henvendelser : SuperModel
{
public Henvendelser()
{
}
public ArrayList getQueue(DateTime start, DateTime end)
{
String sql =
"SELECT " +
" TIDSPUNKT, " +
" NVL(QUEUE,' ') AS QUEUE, " +
" NVL(SUM(ANTAL_KALD),0) AS CALLS, " +
" NVL(SUM(ANTAL_BESVARET),0) AS ANSWERED_CALLS, " +
" NVL(SUM(BESVARET_25_SEK),0) AS ANSWERED_CALLS_25_SEC, " +
" NVL(SUM(INTERN_KALD),0) AS INTERNAL_CALLS " +
"FROM " +
" KS_DRIFT.PERO_NKM_KØ_OVERSIGT " +
"WHERE " +
" TIDSPUNKT >= '" + start+ "' AND " +
" TIDSPUNKT <= '" + end + "' AND " +
" TO_CHAR(TIDSPUNKT,'DY') NOT IN ('AB') " +
"GROUP BY " +
" QUEUE " +
"ORDER BY " +
" TIDSPUNKT ";
ArrayList result = this.getTemplate().template(sql, SqlTemplates.READ_FROM_QUERY);
return result;
}
}
是自动调用的SuperModel
构造函数,还是必须执行某些操作才能确保调用它?
答案 0 :(得分:5)
在您的特定代码中,它是隐式调用的。要明确调用它,您需要使用base
关键字。
在派生类中,如果未调用基类构造函数 显式地使用base关键字,默认构造函数,if 有一个,被暗称。
所以你的构造函数在派生类中:
public Henvendelser()
等于
public Henvendelser() :base()
代码中的其他一些小观察:
List<T>
代替ArrayList