我从平面类扩展了penthouse。我知道当我从扩展类创建对象时,父类的构造函数首先被调用。父类的构造函数不能应用于子构造函数中的给定类型
但我不明白为什么我不能更改阁楼构造函数来初始化只存在阁楼中的新字段。我应该如何更改我的Penthouse构造函数,以免它与Flat构造函数冲突?
error: constructor Flat in class Flat cannot be applied to given types; Penthouse(int new_jakuzi, boolean has_elev){
class Penthouse extends Flat{
int number_jakuzi ;
boolean has_elevator;
Penthouse(int new_jakuzi, boolean has_elev){
cena = 0 ;
address = "unknown";
number_jakuzi = new_jakuzi;
has_elevator = has_elev ;
}
Penthouse(String novi_addrees, int novi_cena){
}
void advertise(){
System.out.println("great penthouse on sale!" +
" number of jakuzi " + number_jakuzi +
" it has elevator: " + has_elevator+
" at price: " + cena) ;
}
}
class Flat{
int cena ;
String address;
Flat(String novi_address, int new_cena){
cena = new_cena ;
address = novi_address ;
}
void show_data(){
System.out.println("cena: " + cena + " address: " + address);
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Flat x = new Flat("bogenbai", 45);
x.show_data();
}
}
是的,我想通了,我不得不总是包括超(new_cena,NEW_ADDRESS)构造函数EVERY我的阁楼建设者! – ERJAN