I program on netbeans ubuntu java standart project (test preparation).
when I create AccountStudent.java I get error.
Account.java
public abstract class Account {
protected double _sum;
protected String _owner;
protected static int accountCounter=0;
public Account(String owner){
this._sum=0;
this._owner=owner;
accountCounter++;
}
}
AccountStudent.java– error: cannot find symbol: constructor Account()
public class AccountStudent extends Account{
}
Fix for problem- add empty Account constructor:
Account.java
public abstract class Account {
protected double _sum;
protected String _owner;
protected static int accountCounter=0;
public Account(){
}
public Account(String owner){
this._sum=0;
this._owner=owner;
accountCounter++;
}
}
Why should i create empty constructor Account if already he exist because he inherit Object class?
Thanks
Constructors are not inherited. If a class has no explicit constructor, hte compiler silently adds a no-argument default constructor which does nothing except call the superclass no-argument constructor. In your case, that fails for
AccountStudentbecauseAccountdoes not have a no-argument constructor. Adding it is one way to resolve this. Another would be to add a constructor toAccountStudentthat calls the existing constructor ofAccount, like this: