java - Difference between Interface And Abstract Class -


why use interface while have given abstract class ?

interface  {      void show();  }   class testa implements {     public void show(){} }  abstract class b {    abstract void show(); }  class testb extends b {    public void show(){} } 

interfaces , abstract classes different in interfaces describe behavior, while abstract classes define partial implementations. interfaces have advantage can implemented object provides necessary method, regardless of classes object inherits from.

abstract methods typically used provide partial implementation. example list interface defines behavior of list collections, compared abstractlist provides of methods needed list implementations, make easier implement list. lists aren't required inherit abstractlist, many implementations do, code uses list never has care whether implementation use extends abstractlist or not.

some people use abstract classes substitute interfaces, considered anti-pattern.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -