interface abstract methods do not specify a body [duplicate]

Methods declared in an interface are automatically public and abstract. So you can start by ditching these two modifiers.

And abstract methods, by definition, do not have a body… So maybe an interface is not what you are looking for here.

If you DO NOT want to be able to instantiate your Printing but want “default implementations”, use an abstract class which provides the base implementation for these two methods:

public abstract class Printing
{
    public void ptr(String print, boolean line) {
        // do stuff
    }

    public void ptr(String print) {
        // do stuff
    }
}

Implementations will then have to extends Printing and @Override the default methods if they want to.

Leave a Comment