0

what's the pure virtual function?what's the constructor function?

public abstract class AmAbstract
{
    private String name;
    public  AmAbstract(){
    }
    public  AmAbstract(String name){
    }
}
L.rocky
  • 69
  • 1
  • 5

1 Answers1

1

The constructors of concrete sub-classes of an abstract class still have to invoke the constructor of their super-class, even when its abstract.

That said, there is no reason for the abstract class constructor to have public access. protected access is sufficient.

public class Concrete extends AmAbstract
{
    public Concrete () {
        super (); // invoke the constructor of the abstract class
    }
    public Concrete (String name){
        super (name); // invoke the constructor of the abstract class
    }
}
Eran
  • 359,724
  • 45
  • 626
  • 694