The following code is a testing program. Why i can’t use A(int a), in this program?
public class A {
int a;
void meth(int b) {
a+=b;
}
A(int a) {
this.a=a;
}
}
class B extends A {
int a;
void meh2(int b) {
a+=b;
}
}
why can’t pass parameter to constructor? What the reasons? Netbeans error message:
constructor A in class tma1.A cannot be applied to given types;
required: int
found: no arguments
reason: actual and formal argument lists differ in length
In the class B, you need constructor. If you mean that you can’t call A from B, that’s just because you’re extending class A, so you need to use super, which refer to the superclass. For example B could be:
Otherwise you need to assign something to the variable a in class B, if you’re not omitting something in code