Is implementation of a standard constructor (Java) necessary in this case?

I have three classes like this:

public abstract class ClassA extends ClassX {
    protected ClassA() {
        super();
    }
    // more code
}
public class ClassB extends ClassA {
    public ClassB() {
        super();
    }
    // more code
}
public abstract class ClassC extends ClassB {
    public ClassC() {
        super();
    }
    // more code
}

I would say that the standard constructor for ClassC is not necessary since Java will insert it during compilation, since there is no other constructor in this class, right? If true, I could simplify the code for ClassC down to this:

public abstract class ClassC extends ClassB {
    // more code
}

Now I'd say that I can't do the same for ClassB since the accessibility of the constructor is increased from protected to public.

I'm asking since I am not 100% sure about this and thought I might be missing something. Especially about the standard constructor that will be inserted into ClassC if I don't implement it myself. In this case it will have accessibility public since it inherits from ClassB. Is that correct?

So my question is: Can I delete the constructor in ClassC without having the code being changed (especially the accessibility of constructors) and is it correct that I can't delete the constructor of ClassB.

Jon Skeet
people
quotationmark

Now I'd say that I can't do the same for ClassB since the accessibility of the constructor is increased from protected to public.

That's irrelevant, given that it's an abstract class. The constructor can't be called directly - it's only used when chaining from a subclass constructor.

So while it would be technically different, your code would be effectively the same if you removed all the constructor declarations.

But in terms of the accessibility of default constructors, JLS 8.8.9 is the authority here:

If a class contains no constructor declarations, then a default constructor is implicitly declared. The form of the default constructor for a top level class, member class, or local class is as follows:

  • The default constructor has the same accessibility as the class (ยง6.6).
  • ...

people

See more on this question at Stackoverflow