I am trying to create a constructor in a subclass which can take the values of data members of its superclass. but I don’t know what is wrong here.
error is saying that ‘method card is undefined for the type creditcard’
class card{
int cardno;
String cust_name;
String bank_name;
public card(int num,String c_name,String b_name)
{
cardno=num;
cust_name=c_name;
bank_name=b_name;
}
card(){}
}
class creditcard extends card{
int limit;
public creditcard(int num,String c_name,String b_name,int lim)
{
card(num,c_name,b_name);
limit=lim;
}
}
>Solution :
Please change your method to the code below:
public creditcard(int num, String c_name, String b_name, int lim) {
super(num, c_name, b_name);
limit = lim;
}
super more about super keyword here:
https://docs.oracle.com/javase/tutorial/java/IandI/super.html
Hope this helps.