Abstract class allows you to define fields so it's easy to implement some stateful base implementation.
In pre-Java 8 there were no default methods in interfaces, so the only way how to provide default method implementation was to create abstract class.
Since Java 8, you can define at interface default methods and static methods, but still there are no fields.
what is the use of a non abstract method in an abstract class
Methods that are not marked as abstract can be used as standard methods in standard class. The reason why you have non-abstract and abstract methods is, that some class functionality (some method) may depend on abstract method. Here is an example:
public class AbstractGreeting {
private final String name;
protected AbstractGreeting(String name) {this.name = name;}
public void displayGreeting() {System.out.println(getGreeting() + " " + name + "!");}
protected abstract String getGreeting();
}
Some concret implementations:
public class HelloGreeting extends AbstractGreeting {
public HelloGreeting(String name) { super(name);}
@Override protected String getGreeting() { return "Hello"; }
}
public class AlohaGreeting extends AbstractGreeting {
public AlohaGreeting (String name) { super(name);}
@Override protected String getGreeting() { return "Aloha"; }
}
And usage:
HelloGreeting hg = new HelloGreeting("World"); hg.displayGreeting();
AlohaGreeting ag= new AlohaGreeting ("World"); hg.displayGreeting();
Sure, abstract classes can be transformed into the interface when you force implementator to return object's state. For example abstract class above can be rewritten as:
public interface Greeting {
String getName();
String getGreeting();
default void displayGreeting() {System.out.println(getGreeting() + " " + name + "!");}
}
Implementation:
public class HelloGreeting implements Greeting {
@Override public String getName() {return "World";}
@Override public String getGreeting() {return "Hello";}
}
But sometimes, it is better to not provide access to object's state, therefore abstract classes might be in some situation more suitable.