Wish to have some nice time? Check out what I'm reading online!

Difference between a Java interface and a Java abstract class?

April 23rd, 2008
  1. Methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior.
  2. Variables declared in a Java interface is by default final. A Java abstract class may contain non-final variables.
  3. Memebers of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..
  4. Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.
  5. An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.
  6. A Java class can implement multiple interfaces but it can extend only one abstract class.
  7. Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.
  8. In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.

5. An interface can extend another Java interface only [...]

It sounds like what you’re saying is that an interface can
ONLY extend ONE other interface?

mjt on December 17th, 2009 10:03 am

No, an interface can extend multiple interfaces.

Probably I should have phrased point 5 as, “an interface can extend other interfaces and cannot extend an abstract or concrete class. Also, an interface cannot implement (but extend) other interfaces”.

Thank mjt for pointing out.

Joe on December 19th, 2009 2:47 pm

please sed this complete ooks for me

zelalem on December 19th, 2009 8:10 pm

if interface object’s initialization with corresponding class instanciation examples would have presented.

Balraj kairamkonda on December 25th, 2009 11:54 am

Instead of picking points from Java books about the differences, it would be better if you describe the main advantages of using interfaces and abstract class, when to use interface and abstract classes. That would add value to your question and make easy understand to the viewer.

Unknown on January 4th, 2010 10:52 am

What Unknown is saying correct.
One more point – If I dont want multiple inheritence then which one is better to use?? Interface or abstract class??

Anonymous on February 11th, 2010 12:41 pm

The point no 8.
“In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.”

What is this “extra indirection”. I have seen same thing in other sites without clear information.

Also How can we prove that java interfaces are slow than abstract classes.

Arun Pratap Singh on March 6th, 2010 8:43 am

simple….read SCJP kathy sierra’s book….best as far as i know…

rakesh on March 9th, 2010 10:50 am

good i lern very much from this sight

abubakar on April 27th, 2010 8:00 pm

thanks for giving expalnation and i need more details about core java

rajesh on July 28th, 2010 11:12 am





hidden and gravatar enabled.