Abstract class implements Interface, can implement more than one interface.

If any new instance method is added in Abstract class then all concrete classes which extends that abstract class need not to provide implementation of newly added instance method. (see Program 4 below)

If any new abstract method is added in Abstract class then all concrete classes which extends that abstract class must provide implementation of newly added abstract method. (see Program 5 below)

Abstract class can have synchronized instance methods, but abstract methods cannot be synchronized.

Even if one abstract method is defined in class than class must be declared as abstract.

Program 1 - Writing your first abstract class

/*

* abstract class

*/

abstractclass MyAbstractClass{

abstractvoid m();

}

/*

* concrete class

*/

/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */

class MyClass extends MyAbstractClass {

@Override

publicvoid m(){

System.out.println("MyClass - m()");

}

publicstaticvoid main(String[] args) {

MyAbstractClass obj=new MyClass();

obj.m();

}

}

/*OUTPUT

MyClass - m()

*/

In the above program MyAbstractClass defines abstract method m()

and its subClass MyAbstractClassprovides implementation of abstract method.

Program 2 - Writing abstract class with no abstract methods

/*

* abstract class

*/

abstractclass MyAbstractClass{

void m(){

System.out.println("MyAbstractClass - m()");

}

}

/*

* concrete class

*/

/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */

class MyClass extends MyAbstractClass {

publicstaticvoid main(String[] args) {

MyAbstractClass obj=new MyClass();

obj.m();

}

}

/*OUTPUT

MyAbstractClass - m()

*/

In the above program MyAbstractClass defines instance method m().

When to use abstract class or interface practically - Choosing between interface and abstract class>

When to use abstract class practically -

Let’s say we have to choose between class or interface for TerrestrialAnimals, than one thing will be for sure that habitat of all Terrestrial animals must be land. That means we can have same implementation of habitat method for all Terrestrial animals. And food of all Terrestrial animals might be different.