【发布时间】:2012-04-22 04:46:34
【问题描述】:
Java 中是否必须调用基类构造函数? 在 C++ 中它是可选的,所以我问这个。
当我扩展 ArrayAdapter 时,我收到此错误:"Implicit super constructor ArrayAdapter<String>() is undefined. Must explicitly invoke another constructor"
那么,调用基类构造函数的目的是什么?当我创建对象基类的构造函数时会调用 & 然后就派生了。
【问题讨论】:
-
您可能没有 rayAdapter
() 构造函数。如果在基类中添加默认构造函数,应该没问题。 -
那么,它是不是类似于 DerivedClass(int x, int y): BaseClass(y), in c++???。对??又多了一个疑问,在上述机制中,基类构造函数类是两次还是一次?