While you cannot make an instance of an abstract class, in this example the super keyword is used to reference the instance variable of the super class, hence a reference that is provided in the abstract class.
`
public abstract class Abstract {
protected int n1;
protected int n2;
public Abstract(int n1, int n2) {
this.n1 = n1;
this.n2 = n2;
}
}
`
same package:
`
public class Instance extends Abstract {
public Instance(int n1, int n2) {
super(n1, n2);
}
public int makeSum() {
return super.n1 + super.n2;
}
public static void main(String[] args) {
Instance myInstance = new Instance(1, 2);
System.out.println(myInstance.makeSum());
}
}
`
Is there an instance of the abstract class created “in the background” – or how do I have to read this?
zozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.