Difference Between Interface and Abstract Class

  1. Main difference is 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. An  abstract class may contain non-final variables.
  3. Members 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.

This Abstract and Interface tutorial was added on 23/04/2008.

«

»

527 Responses to “Difference Between Interface and Abstract Class”

  1. mjt says:

    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?

    • Ansumalini Jena says:

      Java interface inherits one or more than one interface using “extends” keyword.so we called java supports multiple inheritance using interface.

      • Govardhan says:

        Interface can not extend multiple interfaces it implements multiple intefaces
        see the difference carefully.

        • shaffic says:

          Hello Govardhan,

          you are wrong.. interface can extend many interfaces.. while using classes alone interfaces should implement.. dont misguide people.

          thanks.

          • sundar says:

            I verified. What Shaffic said was correct.

          • chinnapa reddy says:

            abstrat class are in java but why interduced interfacess.

          • Anonymous says:

            Dear u r also know that interface is also implement not extend so how can u say that, plz read carefully and than comment ok.. thanx.

          • abhi says:

            please, i m beginner sheffic send me the program

          • abhi says:

            hello shaffic

            this is abhi from kolhapur,
            sir i m beginner in java please send me the example, program of how the interface extends the multiple interfaces.
            regards
            Abhi

        • Rajkumar Chaudhary says:

          Mr.Goverdhan,
          An Interface can not implements another Interface It’s implements by class.An interface always extends another interface like a class extends another class But a class can extends only a single class and interface can extends multiple interfaces at a time.

          • Venkat says:

            I Verified in my project what i working on currently. What Rajkumar Chaudhary saying is absolutely correct.

            public interface InterfaceC extends OnterfaceA, InterfaceB{
            }

        • Ambro says:

          Please Remove Govindan’s comment. That wasted my 30 minutes.

        • Anonymous says:

          how it is possible can u tell me

        • harshad says:

          there are four main senerio to understand the concept of interface or inheritance..!!

          1) interface a
          {
          void f();
          }
          class abc implements a
          {
          public void n()
          {
          system.out.println(“hey”);
          }
          public void f()
          {
          System.out.println(“hello”);
          }
          }

          2) interface a
          {
          void f();
          }
          interface b
          {
          void n();
          }
          class abc implements a,b
          {
          public void f()
          {
          system.out.println(“hello”);
          }
          public void n()
          {
          system.out.println(“hey”);
          }
          }

          3) interface a
          {
          void f();
          }
          class abc
          {
          void n()
          {
          System.out.println(“hey”);
          }
          class aaa extends abc implements a
          {
          public void f()
          {
          system.out.println(“hello”);
          }
          }
          }

          4)
          interface a
          {
          void f();
          }
          interface b extends a
          {
          void n();
          }
          class abc implements b
          {
          public void f()
          {
          system.out.println(“hello”);
          }
          public void n()
          {
          system.out.println(“hey”);
          }
          }

      • Panchanan mohapatra says:

        hi Ansumalini Jena,
        An interface can only implements single or multiple interfaces.It can’t be extend.

        • Panchanan mohapatra says:

          sorry. An interface can extend single or multiple interfaces. Interface can’t be implements another interface.

        • Alok says:

          Hi Panchanan,

          Sorry, but please refresh your concept. Interfaces always use “extends” keyword to implement interface(s) and not “implements”.

          Thanks

          • sahithi says:

            in interface must use implements becoz its an abstract.
            if use extends it shows error at run time

    • Anonymous says:

      An interface can extend anoter interface
      but a class can implements any no of interfaces
      a java class can extend abstract class
      a java class can extend abstract class and implemnts any no of interfaces

    • Prakash Dahagam says:

      can you tell me the situations when we should go for interface and abstract class….?

      • salahuddin ansari says:

        strictly when you want the method to common and use more as required then interface else
        abstract

    • hasnen says:

      YES…INTERFACE CAN EXTENDS THAN ONLY ONE INTERFACE

      LIKE….

      INTERFACE A
      {…..
      }
      INTERFACE B EXTENDS A
      {…..
      }

  2. Joe says:

    No, an interface can extend multiple interfaces.

    Probably I should have phrased difference 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.

    • Ramireddy says:

      Yes,An Interface can extend one or more interfaces but it cant implement any interface

      • Gopal says:

        Is it possible

        public void abstract class Employee
        {
        private String name;
        private String address;
        private int number;
        public void Employee(String name, String address, int number)
        {
        System.out.println(“Constructing an Employee”);
        this.name = name;
        this.address = address;
        this.number = number;
        }

        • Shashant says:

          yes it possible.

          • Anonymous says:

            No it is not possible because abstract class dose not have constructor.

          • Anonymous says:

            Class declaration should not have return type.

          • Mayur says:

            Class should’n has any of return type… including void….

          • moni says:

            Abstract classes can contain constructors.

          • moni says:

            Constructor is a special kind of method inside a java class with the name as class name. It does return anything not even ‘void’.

          • Nikhil says:

            how can a method be implemented within an abstract class…they can be implemented only by child classes…

        • Anonymous says:

          yes why not!!!!!!!

          • Sailendra Narayan Jena says:

            Hi Moni,

            Can you please explain how a Java class Constructor will return. if we are putting any return type before constructor then that is not called as constructor that is called as user defined method. But you have mentioned that “Constructor is a special kind of method inside a java class with the name as class name. It does return anything not even ‘void’.”

            Here you have mentioned that It does return anything not even void. Can you please explain me this line what does this means. But i know if we are creating a constructor inside a class then rules is it should be class name and any access specifier but it doesn’t contain any return type. Like this Examples:

            class A
            {
            public/private/protected A()
            {
            System.out.println(“HI”);
            }
            }

            Here class a contains one constructor which don’t have any return type.

            class B
            {
            public void B()
            {
            System.out.println(“HI”);
            }
            }

            Here class B having two things one is default constructor provided by the compiler and another thing is that its contain one user defined method whose name is same as class name but not a constructor.

            So please explain your line.

            Thanks & Regards
            Sailendra Jena

          • Mohammad Umar Ali Karimi says:

            I hope I’m not beating the dead horse here with my comments.
            Constructors are meant for initialization. That means, you can initialize your instance variables including final ones inside constructors. Constructors don’t return anything. For example:

            class Employee {
            private String name;
            private final Date hiringDate;

            public Employee(String name) {
            this.name = name;
            Calendar c = Calendar.getInstance();
            hiringDate = c.getTime();
            }
            }

            In the above example, I’m simply initializing the name with the param name and final variable hiringDate with the current date. Also, your final variables are assigned the values when the class constructor is called or class is initialized in the JVM. So a class constructor’s job is to initialize instance variables with their default or assigned values. They don’t return anything rather they reside in the JVM for as long as the object is alive.

        • Anonymous says:

          No it’s wrong….

        • saikrishna says:

          yeas we can write

        • mat says:

          “public void abstract class Employee”… what do you mean by void in class declearation

        • pradeep says:

          how a constructor can have return type?

          otherwise this is perfectly fine even abstract classes can have constructors. so its correct.

        • Anurag Kumar says:

          a class as well as a constructor can not have return type,even if not void

          • satheesh says:

            you are right for C++. In java, if you specify void, it will consider it as a normal method instead of constructor.

        • swetha says:

          no its not

        • Anonymous says:

          No,I think it won’t work as an abstract class cannot be instantiated..how this constructor can get executed…

          • Anonymous says:

            It is valid. Here “public void Employee(…)” is a method which is having the class name but its not the constructor.

          • Manoj says:

            Abstract class can have constructor,we use it for varible initialization and also for constructor chaining.

        • Anonymous says:

          it is not possible, b’caz class returning void,

          • Anonymous says:

            constructor dose not have any return type,
            we can not create a object of a abstract class so how constructor will get called?

          • Bhushan says:

            constructor dose not have any return type,
            we can not create a object of a abstract class so how constructor will get called?

          • Bhushan sak says:

            constructor dose not have any return type,
            we can not create a object of a abstract class so how constructor will get called?

        • Pradeep Kumar Verma says:

          it is not possible because any class does not have any return type…

        • Ravi says:

          It wont work becoze its class and constructor have return type…which is not a valid,i think so…

        • Naushad says:

          The code is wrong because class cannot have return type void. If it is typed by mistake, than the code is perfect. If you write a method with the same name as class with return type it does not qualify as construtor. The compiler will concider it as a normal method. So the code is perfect. It can used by subclassing it and passing the arguments in method Employee.
          Hope it answers the query.

          • aman says:

            1. class acn not be void.. its not allowed
            2. you can use a method with same as class name
            hence public void employee is ok
            3. you cannot create object of class employee as it is abstract class but calling private memer by this pointer is allowed …

            so finally just remove void from class declaration
            nd it will work ..
            just don’t create object and don’t try to invoke method :-)

        • Anonymous says:

          no it’s not possible.

        • @naim says:

          yes!.. y nt. object class is der.. so it is true

        • Rushik Sutariya says:

          ya friend this is possible.
          we can use of “this” keyword here.

        • Anonymous says:

          no because not hav return type of the class

        • Anonymous says:

          public void Employee(String name, String address, int number)
          The abovecode is not constructor because it is returning void while constructor never return type..

          Anil Kesarwani

        • Parag says:

          There should be at least one abstract method in the class

        • Smruti says:

          The class declaration itself is incorrect.

          It should not be “void key word”

    • Anonymous says:

      extends means one abstract class or one simple class

    • chinna says:

      hi
      this not possible,because constructor not come return type and than abstract class there also no return type so this code is error

  3. zelalem says:

    thanks for the abstract and interface difference ..
    please send this complete book for me

  4. Balraj kairamkonda says:

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

  5. Unknown says:

    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.

  6. Anonymous says:

    Excellent tutorial on abstract and interface difference
    One more point – If I dont want multiple inheritence then which one is better to use?? Interface or abstract class??

    • chinju says:

      interface is better if you don’t want multiple inheritance because Because if you add new method headings to an interface, then all of the classes that already implement that interface will have to be changed to implement the new methods.

      • Manoj says:

        I think in this situation abstract class is better option.Becaause it is easy to add new functionality in abstract class and modify it in the child classes.but in case of interface u r bound to implement the methods in the class though ur classes dont need them.

  7. Joe says:

    @unknown – I was just trying to reproduce the theory in a simple way as in my style.

    But, apart from this list of difference, I will write a separate article on when to use interface and when to use abstract class

  8. Arun Pratap Singh says:

    The difference 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 difference point in other sites without clear information.

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

  9. rakesh says:

    to know more about the difference between interface and abstract class ….read SCJP kathy sierra’s book….best as far as i know…

  10. abubakar says:

    good i learn very much from this webiste

  11. rajesh says:

    thanks for giving explanation and difference between these two and i need more details about core java

  12. Sean, melbourne photographer says:

    Hi,
    some nice tips on this site!
    I also don’t get difference 8 though – can you clarify please?

  13. raghu says:

    how to utilize interface in another class without implementing that interface

    • Anonymous says:

      You have to define the interface from where you need the interface implementation ForEx. To write a thread program need to implement Runnable or to extend Thread .The other way is as follows .

      Runnable r = new Runnable(){

      public void run()
      {
      //Do you thread code here
      }
      };
      new Thread(r).start();

  14. Argha Basu says:

    It’s good, lists the complete abstract and interface difference in simple way

  15. maxmetallica says:

    Hey Raghu,you can do that by making the implementing class abstract and then extend it in another class of your choice .

  16. Manish says:

    apart from difference between them,
    use Interfaces when you require 100% abstraction otherwise use abstract class

  17. Manas says:

    Why interface cannot be instantiated?

    • Ankit Kumar says:

      we can not create instace of an interface because it hava incomplete methods. so can not provides sufficent memory by the jvm.

  18. why a default constructor is provided by jre in java

  19. monika bansal says:

    thanx for the complete abstract and interface difference thing… its good, it helps me alot

  20. Hema says:

    Your website looks so good..

  21. subbu says:

    Hi,

    We can also discuss like an interface will be used for an object reference of its implementing class while abstract class object reference can be used for its extending class.

  22. mohan says:

    your explanation is very good
    please send me the whole book

  23. Joe says:

    There is no book. But I have an idea of coming up with something in the future.

  24. yogesh says:

    interface is the most powerfull solution of using multiple inheritance because java does not support multiple inheritance

    Thank you

  25. rajesh says:

    good explanation but
    explain new topics on java

  26. amit kumar says:

    Thank you…very much……..
    please…..
    send me one copy of this book.

  27. niyaz says:

    ya i accepted this concepts and more useful for beginers……..

  28. shafi says:

    Hi.
    can u give me the difference between the two following statements

    1.A sub1=new B();
    2.B sub2=new B();

    where A is suerclass
    B is the sub class

    //method over riding
    class A
    {
    int i,j;
    A(int a,int b)
    {
    i=a;
    j=b;
    }
    void show()
    {
    System.out.println(“super”);
    System.out.println(i);
    System.out.println(j);
    }
    }

    class B extends A
    {
    int k;
    B(int a,int b ,int c)
    {
    super(a,b);

    k=c;
    }
    void show()
    {

    System.out.println(“sub”);
    System.out.println(i);
    System.out.println(j);
    System.out.println(k);
    }
    }
    class Override{
    public static void main(String args[])
    {
    A sub1=new B(1,2,3);
    B sub2=new B(1,2,3);
    sub1.show();
    sub2.show();

    }
    }

    • Pradeep Kumar Verma says:

      1)it call the constructor of class B by passing the arguments(1,2,3) and it assign the reference variable of class A type
      2)it call the constructor of class B

  29. venkat says:

    first you have to concentrate on Polymorphism concept , why because if you are crating the object and the object reference is give to super class , then on that time it checks whether that method is there in subclass or not at compile time

  30. Chandrashekhar says:

    plz write a default construcctor in side class A then above code compile and run successfully………..

  31. Chandrashekhar says:

    example is nothing but a polymorphism………

  32. sindu says:

    thanks it is very useful.

  33. ramakrishna says:

    thanks for clarrification

  34. Remya says:

    When to use abstract class over Interface ?

    Thanks in Advance
    Remya

  35. Aryan Nardiganj says:

    its a great help for understanding main difference between both abstract class as well as interface.
    to know more about the difference between interface and abstract class ….

  36. manish says:

    plz mail me the difference in abstract and final keywords in java

  37. vivek kumar says:

    what is difference between overloading and overriding?

  38. RaamNaresh Reddy says:

    Wow… it is too good Blog..

    it is too Elegant..,
    Conceputally Nice…,

    I like the Way u explain about “Difference between Abstract class and Interface”

    What my suggeation is…, Write one Example Program For Every Explanation..

  39. Thadeuse says:

    thanks for ur explanation

  40. Thadeuse says:

    is it possible
    abstract class A extend b implements c
    {
    }

  41. trupti says:

    thanks for explain it

  42. Uma Karmakar says:

    thanks for the basic help in java

  43. Hari chowdary says:

    How many maximum number of Interfaces are implements in our class?

  44. Rahul Jaiswal says:

    Hi….. It is too good.

  45. meena says:

    Hi Joe,
    This is very useful.Being a fresher its very useful for me. Mainly the website design is really fantastic.Keep going……….

  46. sam says:

    why abstract class does not support for the multiple inheritance?

  47. Asha.BM says:

    Please mail me this book.

  48. Lokanath says:

    Thanking U for providing a comprehensive information. may allmight with u to have ur destiny.

  49. rajitha says:

    hai
    very nice and good.

  50. Zeeshi says:

    Thanks it was a little helpful for me….

  51. Zeeshi says:

    Difference B/W overRiding and overLoading:

    in over riding perameters and type of method remain same. but its internal properties changed you can say over ridden.

    in over loading the name of method is same but parameters are different. according to type or in number. the call to these functions depends on the parameters compatibility…

  52. kousalya says:

    dis infermation is very well and easy to understanding…..i am feel good………

  53. guest says:

    the main difference is interface doesnot talks about implementation.it talks about requirement specification
    abstract class:
    it talks about implementation but not completely(partial implementation).

  54. satnam singh says:

    Hi readers,
    i go through all above mentioned discussion regarding interfaces and abstract classes. So i feel some person need example where to use interfaces . In order to understand the interface concept just thinking that how jdbc api worked with each and every dbms(oracle,mysql etc) because jdbc api provide just interfaces and implementations of these interfaces are provided by the dbms vendor that implementations are known as database drivers. (9888327755-ssubhi_2003@yahoo.com). Feel free to discuss any java topic

  55. Rajanikanth says:

    thanks

    dis infermation is very well and easy to understanding…..i am feel good………

  56. Mansi Singhal says:

    well written

  57. Kavan Vakhariya says:

    Easy and point wise description help me to understand the exact difference.

  58. Anonymous says:

    Im ery helpful to all, this discussion has provide me clear knowledge.
    yes and i most lke info provided by satnam singh, you know we were using that but never came in mind that how basic java get used over there. great….

  59. Guest says:

    nice artiacle and very helpful also…Can anybody explain why java interfaces are slow and how it requires extra indirection??

    Thanks in advance.

  60. Madhuri Gorde says:

    All the above mentioned pts. are totally easy to undertand.

  61. ganesh says:

    hii can any one help me to know how interface is slower than abstract abstract class.
    in the above article what indirection means?

  62. arxlan ahmed says:

    Really nice points to understand thanx

  63. Swetha N says:

    Could you please give some program examples, about their diffrences

  64. krishna says:

    hi i through all above ur’s feedback pls can u people send me what is difference between class interface and abstract class
    send me j-krishna@live.com

  65. kasthuri says:

    how multiple interface is used instead of multiple inheritance??

  66. venkatesan.g says:

    before studying this information i am not clear about interface and abstract class.just now i am know about this topic.thank you

  67. Yashas says:

    Neat & Clear!!! Information provided can be understood by even a average student.

  68. Anonymous says:

    i need a difference between a class and a interface?

  69. Rajesh Kumar says:

    Very well written article

  70. Justin says:

    All of the variables in an interface are implicitly static and final.

  71. kathirvelan says:

    hai guys, how to use in spring with struts?

  72. ppp says:

    nice info

  73. Deepak says:

    thanxxxxxxxxxxxxxxxx

  74. wtd says:

    all i saw was jibber man.. please for heavens sake , use examples…!

  75. Sayyed Imam says:

    Mr. Satnam Singh explained very well…..so nice

  76. Jeetu says:

    thats good, i understand the difference between interface and abstract class.
    but can you give a code which show the difference ……

  77. Anonymous says:

    Easy to understand

  78. srikanth venigalla says:

    its very helpful to me thanqs for your kindly info…….

  79. srikanth venigalla says:

    its very help to me .thanqs fro your kindly info…

  80. mohit says:

    nice difference between interface and abstract class

  81. shree says:

    i have a doubt, if we implement an interface need to write all the methods in that interface even if we don’t need the methods .what is the case of abstract class?

  82. Joe says:

    Thank you all for your great comments!

  83. ankit says:

    thanxxx

  84. T.PRIYDARSHINI says:

    plz send me the complete tutorials so that it will helps me a lot

  85. Pankaj says:

    Thank you so much for giving the best Answer…

    because of i am so confused
    Thank you again.

  86. T.PANDEESWARI says:

    abstract class and java class both are same or different???

  87. Selva says:

    HI Joseph,

    Let me know that why we are choosing “Interface” & “Abstract class” for a good application..

    Thanks in advance,
    Selva

  88. neeraj tanwar says:

    hiiiiiiiiiii joseph,

    what is we commoly use in java project that is absruct class or interface?

    my second question is that what the actuall meaning of implimentation and extand?

  89. ruchi says:

    my first ques is 1)6 points of difference between object and class.
    2)6 points of difference between dynamic binding and message passing.

  90. ruchi says:

    ques) explain briefly why cant we use a keyword as a variable name???

  91. ruchi says:

    tell me true or false…
    1. when if statement are nested,the last else gets associated with the nearest if without an else.
    2. one if can have more than one else clause.
    3. a switch statement can always be replaced by a series of if…else statements.
    4. a switch expression can be of any type.
    5. a program stops its execution when a break statement is encountered.

  92. manas sahoo says:

    very very good explanation on the differences

  93. VipinJeet Tripathi says:

    This is quiet good….
    It may be useful for interview…

  94. sushil says:

    very accurate answers.good.

  95. harshil says:

    very nice answers good

  96. soma says:

    This is really good….
    It is useful for interview

  97. Rajan E says:

    Its so easy to learn even if the people doesn’t know java

  98. Samantha says:

    This is really helpful!!

  99. Shitansu says:

    Hi Joe,

    Can you please tell me when to use Abstract class and when to use Interface in an application?

  100. vinod says:

    give reallife example of interface…….

  101. Anonymous says:

    hey i didnt get my answers,,,,,,,,,,,,

  102. khushboo says:

    thank u sir

    plz mail me similarities between an interface and classes

  103. jessie143143 says:

    In interfaces we cannot have any implementation for methods but that’s not the case with abstract classes we can have implementation for methods.

  104. mani says:

    thank you for giving informations
    but i want more details …..

  105. ramesh says:

    nice explanation for interface and abstract class

  106. sampath says:

    about java buzz words ?

  107. vinoth says:

    It is very use full for me….. Thank you… by V.Vinoth from poondi

  108. Ahmad says:

    Thank you very much … it was very useful to me

  109. sai says:

    thank u for giving this wondarful information

  110. Praveen says:

    Hi Joseph sir,

    Thanks for the detailed explanation of diff between abs class and interface. I would like to know , on what basis programmer deside he need to use interface or abstract class ? and if interface is having 2 abstract methods(only) and abstract class is having 2 abstract methods(only) then what was the difference in both ? Please post answers for the questions.
    Thanks and Regards,
    Praveen G

  111. Anudeep says:

    Very helpful…

  112. karabi das. says:

    plz give me the 6 points of difference between messege passing and message binding……..

  113. srividhya says:

    i still have a doubt, when we have to use interface and when we have to use abstract(class as well as method)

  114. ana says:

    plz suggest me how can i become expert in making programs by myself?? because coding postion in java is a biiiiigggg giant for me can u suggest how can it be easier for me the coding in java

  115. swati says:

    nice web site

  116. sabrina says:

    its really helpfull for my class lacture

  117. mayank jain says:

    what is the main reason to create abstract class?…..
    sir i know we cant create object of abstract class and we also provide method body in abstract class compare to interface…

  118. Anonymous says:

    good and simple

  119. Anonymous says:

    difference b/w instance variable and class variable.

  120. jangbahadur patel says:

    what are the changes to a variable ,method and a class when a final keyword is added to them.

  121. jayashree says:

    I was put forth this question in the interview.Please help.

    When you have to pass the data in the form of keys which collection would you use ?

  122. Thirupathi says:

    thank you for information about abstact class and interface

  123. ram kumar says:

    Apart from these differences one more difference is in my mind, i want to ask is it correct or not-

    * interface can be declare as a member of a class while abstract class is’t.

  124. vivek bhatt says:

    some interface define just constants and no methods……thanks 4 giving such simple and good differences….can u send me whole book on my given id….plz…..

  125. Mahesh Reddy says:

    can u send me the real time example that when do we use interfaces and when do we use abstract class

  126. samson says:

    Its very easy and useful to me

  127. Muruga G says:

    One more point:

    1. If we created Interface we can add new methods easily, but abstract is not easily.
    2. Interface act as Service layer its interact different types of two entities(node) but abstract is not.
    3. Interface is high level of abstraction(fully abstract class) but abstract is next level of abstraction.

    I have added some point. Please verify and let me know if it is correct or not?
    Please forgive any typical and grammatical mistake.

    Please send me if any feedback: murugadoit@gmail.com

  128. Arabinda says:

    Abstract class start with letter “A” and Interface starts with letter “I”.

  129. Shaleen says:

    What is the purpose of using Abstract class????

  130. Jayaram says:

    Hi,please provide the Real-time examples for Interface and the Abstract class.So that every one can understand easily..

  131. Balachandiran says:

    Hi Joe ,
    when we have to use abstract class & interfaces can you explain

  132. mallika.oleti@gmail.com says:

    If i create any reference variable to an interface and also i create the object of implementing the class.just mail me the difference

  133. shiv says:

    Hi Joe,

    First of all its a nice blog. Congrats for writing and maintaining this blog.

    On Dec 19th you have mentioned that “an interface can extend multiple interfaces”.
    But java doesnt support multiple inhertance. Please explain your statement.

    With Regards
    Shiv

  134. maagi says:

    thanks joe for detailed explanation

  135. Vijay Yatham says:

    good explanation

  136. Rajesh says:

    Hi All,

    I am new to java. Can you please explain what are the topics covered in J2EE? if i want to serve in Java field, what are all i need to learn..

    Please help me.
    -Thanks in advance

  137. Rajesh says:

    Hi All,

    I am new to java. Can you please explain what are the topics covered in J2EE? if i want to serve in Java field, what are all i need to learn. and also please explain the ways

    Please help me.
    -Thanks in advance

  138. Sandesh says:

    what if abstract class implements two interfaces then it has to provide bodies for method declarations in interfaces or not?

  139. Anonymous says:

    when we have to use abstract class & when we have to use interfaces can you explain

  140. bharath says:

    Thank you,that the difference between them is clearly understood to me.Please explain in simple programatic way?

    when we have to use abstract class & when we have to use interfaces can you explain?

  141. vishnugandhi says:

    Thank you for clearing doubts…..please send this book to my mail id…i have some more doubts

  142. Venkatesh Bestha says:

    This differences can be found everywhere, say new things like
    1. when to use Interface and when to use Abstract class
    2. which one is efficient ?

    Just give some practical programming scenarios.

  143. Anonymous says:

    hello nyc blog

  144. keith says:

    hiiii gud source of info……keep goin!!

  145. Anonymous says:

    catch
    {quotient=divide(num1,num2);
    cout<<"The quotient is "<<quotient<<endl;
    }
    try(char *exceptionString)
    {
    cout<<exceptionString:
    }
    wat is the error in this code……..

  146. rajesh says:

    Thank you sir it is really helpfull to me keep going on………..

  147. Pranav Thipse says:

    Thanks a lot !!!!!!!!!!!!
    you are The Best.
    Thanks for writing and maintaining this nice blog. this is very nice blog.

    pranav thipse.

  148. Sujay says:

    Hi Sir, really good blog.Very much impressed by the blog and the information displayed.It would be nice if you can start covering advanced topics also in this blog.

  149. Kiran says:

    Hi joe,
    I know about Interfaces & Abstract classes. But can you please let me know why there are 2 different things Interface & Abstract class. When only Interface was enough(I guess, to do all the work.)

  150. pritz says:

    i stil hav a lot of doubts.can u jst giv some example and also show whn to use wht?

  151. Anonymous says:

    it was really nice and in a very simple language… thanks joe

  152. saravanan says:

    can any1 give me A simple program for managing abstract and interface which includes all aspects as joe said?

  153. neha says:

    can any body explain me constructor in detail…i don’t no the use of it pls. explain me..

  154. siddu says:

    Thanks joe really helpful,But I’m having confusion about the term “extra indirection” used in 8th difference can u please explain what it is ?

  155. indian freak says:

    I have a doubt Joe,

    In my current coding, my aim is to call the same method in different classes simultaneously. say class1 and class2 access add()method present in class3. My issue is a null pointer is getting displayed on execution. Can u guide me on this???

  156. yogesh says:

    can you please explain how the servlet communication done to other? explain different ways ?

  157. Anonymous says:

    Thanks you for giving to this this answer.

  158. pazuzu says:

    Some simple examples would be really great :)

  159. Anonymous says:

    this is awesome. thanx

  160. Anuj says:

    Please any one explain ,where we use Abstract calss and where we use interface .
    Plese give example

  161. Rajeev Kumar says:

    is an interface implicitly an abstract class?

    Thanks…

  162. Anonymous says:

    any book to get a good knowledge of java in simple and easy text?

  163. rakesh says:

    hi thanks for differences of abstract and interface .please send the complet book to my mail id are the address in url pattern (rakesh.gandua9@gmail.com)

  164. Anonymous says:

    hiii,,,,thanku for u r description plzzz send the java book which can be helpful in the basics point of view to my email id (kalyaniapple93@gmail.com)

  165. navi says:

    In the 7th difference pls give an example that how can we invoke abstract class if main exist…

  166. anjani says:

    pls send the best book for core java to my mail id i.e. anjaniatmakuri@yahoo.com

  167. Matheen says:

    Nice work again…but i don’t understand 7th difference,can u explain me in detail.

  168. Arjun says:

    Is it possible to implement Iterator interface
    Methods in our own class?
    for example

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package Collection;

    /**
    *
    * @author arjun gm
    */
    public interface java.util.Iterator {
    public abstract boolean hasNext();
    public abstract E next();
    public abstract void remove();
    }
    public class MyInno implements Iterator {
    boolean hasNext()
    {
    System.out.println(“Add”);
    return true;
    }
    void remove()
    {
    System.out.println(“Sub”);
    }
    public static void main (String args[])
    {
    MyInno my=new MyInno();
    my.remove();
    }
    }

  169. Musaddiquie Husain says:

    why variables declared in interface are final by default and why all members are public by default?

    when and where interfaces and abstract class is to be use?

    Thanx…..

  170. Alps says:

    nice explanation .Can u tell me how can we instantiate Abstract class

    • satish says:

      by extends that abstract class by concrete class means public class classname extends Abstract class.
      sub class that extends super abstract class
      we create object to sub class that is also called super class object becoz super class behaviours and methods all came to sub class so it is also super class object

  171. Bhaskar says:

    No, you cannot instantiate an abstract class. An abstract class is a class that is not yet “finished” – it contains methods without an implementation. A non-abstract subclass is supposed to implement those methods

    You can create anonymous subclasses that implement all abstract methods:

    AbstractAction action = new AbstractAction(“Hello”)
    {
    public void actionPerformed(ActionEvent e)
    {
    // this is the only abstract method in AbstractAction
    }
    };

    These anonymous subclasses only support the constructors of the abstract class though, you can’t create your own ones. If you need that kind of behaviour you need to create actual subclasses

  172. Java Learner says:

    Joe, Can you please re-design the site to help the user to reply to a specific comment, rather than commenting in end.

    It would help people in following better, to the question/tips left by fellow contributors

  173. Joe says:

    @Java Learner, yes I need to make that change so that we can reply to a particular comment. Sure I will do it as soon as possible.

  174. Swami says:

    theoritically good .try to show it with examples….

  175. prakash says:

    Thanks a lot !!!!!!!!!!!!
    is very useful for my exam preperation
    Thanks again

  176. appu says:

    Thank u very much…… this explanation is short pls put more anyway thanks guyz

  177. Reshma says:

    such a nice example for prepare an interview

  178. Aricent says:

    Hi all,
    I came to know that most of you are clear with the differences. Can anyone of you explain this point,“In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.” Even i read in several sites interfaces require extra indirection and hence slow. why is it and what is indirection,

  179. shiva says:

    nice one but give one example

  180. javabean says:

    when we use abstract class? and when we use interface? pls reply

  181. Anonymous says:

    Can you please explain with an example for both abstract and interface? It is very useful and easily understand

  182. Anonymous says:

    thanks man u are great!!

  183. Anonymous says:

    perfect….dude….

  184. Manoj Singh says:

    when do we use interface and abstract class ?? what is the necessity of using both of them differently if they are similar to each other ?

  185. karthik says:

    where should we use interface and Abstract?

  186. Koray says:

    are you alive

  187. Anonymous says:

    grt site.

  188. kiran says:

    thanks for yr dis ans………

  189. ravi says:

    Please let me know how the abstract class is faster than interface

  190. Anish says:

    Very helpful site. Will share it on facebook :)

  191. Bimal Modak says:

    Interface Requires more time to find the actual method in the corresponding classes.
    this is why Abstract class implementation is faster than interface

  192. lalit says:

    abstract class does not have a body

  193. chirag pandey says:

    sometimes a problem occurs where we have to only define methods in abstract class,but using only methods in a class is against an Object-oriented concept.that is the reason we use interfaces..because interface is not a class so we can easily put methods in an interface.

  194. pawan kumar says:

    why we use interface or abstract class and what is the best approch interface or abstract class

  195. amit says:

    This is really useful

  196. jasmy jose says:

    Thanx a lot

  197. Srinivasulu says:

    plz send me some java course materilas, i am learning initial stage and i need not take any training, i have learn java my own thats why please send me some course meterial that materials useful my starting stage.

    plz avoid authors books

  198. Sanjay Patel says:

    Is it possible to implement Iterator interface
    Methods in our own class?
    for example

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package Collection;

    /**
    *
    * @author arjun gm
    */
    public interface java.util.Iterator {
    public abstract boolean hasNext();
    public abstract E next();
    public abstract void remove();
    }
    public class MyInno implements Iterator {
    boolean hasNext()
    {
    System.out.println(“Add”);
    return true;
    }
    void remove()
    {
    System.out.println(“Sub”);
    }
    public static void main (String args[])
    {
    MyInno my=new MyInno();
    my.remove();
    }
    }

  199. Sakthivel says:

    Thank u for useful information

  200. Mayank says:

    Can we extends the interface ? if yes then show me by one example if no then tell me a proper reason ?

  201. aashraye rai says:

    thanks

  202. Susagar says:

    Thank you for giving the nice info….

  203. seenu says:

    its a useful tutorial

  204. seenu says:

    its a useful tutorial

  205. Anonymous says:

    thanks for giving valuble information…….. friends please send some more java material to me my e-mail is:govind.588@gmail.com

  206. Jzeet says:

    Thank you for providing us these answers

  207. Anonymous says:

    if any interface is enxtend the same abstact method with in the abstract class then what will happen……. how? please send me one example////

  208. Francis says:

    What is the significance of Interface?

    Its just a declaration of method names. But the implementation is still in the class.

    Any one can answer?

  209. Ajay Patil says:

    joe .plz explain
    how transient keyword works with small example and what do u mean by serialization

  210. anu says:

    hi joe
    can i know exact usage of both interface and abstract class?

  211. Anonymous says:

    hai joe sir,
    Iam a begginer in java,before reading this blog i had lot of confusions in my mind now I got clear idea about interface and abstraction.Thank you so much for that……can you plz include some examples(programm).

    Biji A

  212. josh says:

    Nice blog:)

  213. sid says:

    hi Guys ……

    My Question : Can Over riding supports Inner classes in java?

    package com;
    public class Test
    {
    public static void main( String[] args )
    {
    A b = new B();
    System.out.println( “Calling b.test(): ” + b.test() );
    B b1 = new B();
    System.out.println( “Calling b.test(): ” + b1.test() );
    }

    private static class A
    {
    public static String test() { return “A”; }
    }

    private static class B extends A
    {
    public static String test() { return “B”; }
    }
    }

    if you need any help in java … contact me …

    siddardhas@yahoo.co.in

  214. avdhesh samele says:

    examples are good for me……*

  215. Munna says:

    nice blog..

  216. priti says:

    thanks

  217. Anonymous says:

    not bad

  218. Bala says:

    pls include some examples

  219. Anonymous says:

    thank u…

  220. Akshit says:

    Thanx for difference …
    it is help me lot in tomorrow exam of java ….

  221. SANKARGANESH L says:

    thanks…It is very useful….

  222. imran says:

    thanks a lot it is helpful for my exam

  223. Nagarjuna Reddy.M says:

    Could you Please Explain Difference Between Interface and abstract class with real time example?

  224. malli says:

    i think 5 point i have doubt

  225. Srikanth K says:

    malli,
    “i think 5 point i have doubt”
    coming to your Qestion

    Class A extends Class B(abstract class)
    {
    // Class can extend only ONE Class
    }

    Class A implements Interface A, Interface B, Interface C {
    //Where as Class can implement Multiple Interfaces
    }

    Hope you are clear now

  226. pramod says:

    hi, sir

    i have recently complete my MCA and Join a company as java programmer, but i dont have knowledge of java, and i dont have much time to join coaching, so is there a way to learn java pls suggest me some sophisticated way to learn java programs…..

  227. sudhir says:

    Good initiation

  228. Farhan Munir says:

    Very useful and very clear. Thanks.

  229. Vijay says:

    1 more diff=
    An interface cannot have a constructor whereas an abstract class can have a constructor which is called indirectly by the derived class.

  230. ertet says:

    Good

  231. anand says:

    its good

  232. ram says:

    its very useful for all.
    thanks

  233. Anonymous says:

    hmmm have to improve

  234. Sreejith says:

    hmmm have to improve

  235. Anonymous says:

    its usefull to me… thanks..

  236. Rawinder dhillon says:

    thx

  237. Ramaseshan says:

    Proud to see a chennai guy coming up with lot of info..

    Generally only Americans do this…

    Thanks a lot…

    Ur website is very interesting and attractive….

    If u cannot share ur pone number pls call me at 9543111591.
    I wanted to ask u some doubts..

    Ramaseshan , Chennai

  238. akanksha mathur says:

    sir can u plz explain the difference between an abstract class and an interface through a small program… i mean can u plz give me a code which can only be implemented by using an interface not by using an abstract class…???

  239. Mallikarjuna says:

    when to use abstract and when to use interface would you explain with an ex. sir

  240. [...] wrote an article describing difference between abstract class and interface. Lot of people are asking for example with a nice usage scenario. JDBC is a direct and excellent [...]

  241. Mayur Kumar says:

    Hi sir,

    i like your blof content very much. but i would like if you would give some practival scenario laong with the points. likw e.g whne Interface is good and bad. same for teh ABSTRACT classes. which one to choose when. specially we are open to both.

    Thanks in advance..

    | Mayur Kumar

  242. Anonymous says:

    Can you please explain about when to go for interface and abstract class?

  243. Shailendra kumar shail says:

    Hi Joi,
    I have my own doubt if you can clarify.

    When we compile a class or interface java create .class file.

    For example if we create Test.java and it contains
    public class Test{….}

    in other file if we create
    public interface Test{….}

    on compilation both file will be created as .class then how can we know that whether we need to extends or implements if we don’t have any IDE.

    Thanks.

  244. Anonymous says:

    These r text book differences write some real time orientation sir…………

  245. Rakesh says:

    great job…. :)

  246. Understand clearly but,i need when to use interface and when to use abstract?
    with program?

  247. Java_Gun says:

    JOE dear,
    In Diiference # 3. You have added that the Abstract Members can be Private Flavour..is that possible to have Private Method in Abstract Class…???????

    If your Answer is Yes Please Post executable Code…

    • selvakumar says:

      Hi,
      We can have private method as we can call the private method inside another non abstract method.:)

  248. Priyanka says:

    Why we have only final variables declared in an interface?

  249. N.rajlaxmi says:

    I want miniproject title in core java..please suggest me.

  250. Javaid says:

    @priyanka

    Answer to you question

    All variable in interfaces are final by default

  251. shyam says:

    could you please explanin me the exception handling concepts

  252. udhaya says:

    Quiet Good… Interesting.

  253. Anonymous says:

    Its said like interface can have private members and default is public. But, I don think its true. Can anyone please confirm this??? Can interface have private members??

  254. Anonymous says:

    Sorry for the wrong information. It was a misunderstanding. Kindly ignore!!!

  255. Raman K says:

    very useful to me thanks

  256. muthu says:

    yes its usefull thaks …

  257. Anonymous says:

    really good …. thank you…..

  258. yogesh says:

    thanks for this explanetion
    thanks so much

  259. sanjeev says:

    what is return type of constructor in a java

  260. roshan says:

    constructor can’t have any constructor….

  261. Rajeesh.N.Santhu says:

    @Sanjeev

    Constructor is not a method, so it cannot have a return type, but can have arguments and access modifiers.

  262. nnn says:

    in point 5 the statement is there interface can extends another interfaces but interfaces are used using implements keyword

  263. nnn says:

    can unterface can be use through extends keyword because extebds is use for only classes

  264. Anonymous says:

    Nice to Learn.

    Thanks,
    Udhayakumar G K
    http://saijava.blogspot.in/

  265. Anonymous says:

    it is gd

  266. Anonymous says:

    you are telling differences
    but not telling about the correct features like where do we use abstract and where do we use interfaces in real time scenarios?

  267. kaviyarasan says:

    please clear with the example programs for abstract class and interface

  268. Tony says:

    Hi Joe

    One of my sincere request can u give a real time scenario where to use abstract class and where to use interface.

  269. pritha says:

    very useful to me…
    Thanks a lot………….

  270. Bhushan says:

    When to use Abstract and when to use Interface ?

  271. Shahjahan says:

    Hi joe

    A Java abstract class can have instance methods that implements a default behavior.

    I Can’t understand what that means please clarify using some example.

  272. Shaique says:

    This explanation is good but, can you explain when to use interface over abstract class and when to use abstract class over interface ..

  273. Vishaka says:

    Hi Joe,
    – One more difference between Interface and Abstract class is that:

    Abstract class contain Constructor Where as Interface does not contain Constructor.

    If any mistake is there then PLZ let me knw.

  274. nagajothi says:

    what is the difference between Interfaces and abstract? please give the real time example ?

  275. nagajothi says:

    when to use interface and when to use abstract class? please send the clear example sir?

  276. mano says:

    why is abstract class is needed?everybody says for extending a common functionality throghout the application we define an abstract class with one concrete method which holds the common logic and extend this abstact class.we can define a concrete class and subclass it..right?.what is the real need to define an abstract class here?

  277. Anonymous says:

    you are the best joe………

  278. Anonymous says:

    wow….it is too good

  279. M Abbas says:

    Nice discussion

  280. NEERAJ KUMAR SINGH says:

    nice

  281. droni says:

    hello ,this is a good information to know about interface and abstract class.pls send me a copy of these java papers.

  282. muni says:

    very nice

  283. srinivas battineni says:

    when we should go for interface and when we should go for abstract class?

  284. OVERRIDDING-when you extend a class and write a method in the derived class which is exactly similar to the one present in the base class, it is termed as overriding.
    EX-
    public class BaseClass{

    public void methodToOverride()

    {

    //Some code here

    }

    }

    public class DerivedClass extends BaseClass{

    public void methodToOverride()

    {

    //Some new code here

    }

    }

    OVERLOADING-More than one method, in the same class shares a same name but different arguement is called overloading..
    EX-
    public class OverLoadingExample{

    public void add(int i, int j)

    {

    int k = i + j;

    }

    public void add(String s, String t)

    {

    int k = Integer.parseInt(s) + Integer.parseInt(t);

    }

    }

    You wanna learn html visit http://htmlatul.host56.com

  285. RKG says:

    Good explanation.

  286. sai says:

    Thank you , more helpful

  287. prathamesh says:

    it’s really valuable……….
    thanks to you for explanation………

  288. Palanikumar says:

    Respected Sir,

    I want talk to you.I have more doubts please clear to me. your explanation is okay but u dont mention realtime and practical information

  289. abc says:

    Informative site….

  290. P.Vijayakumar says:

    Sir,i have one doubt with abstract class..
    Why we need abstract classes in java??..

  291. Anonymous says:

    how do we pass values for concrete methods from main function in abstract class

  292. Kumar says:

    Very nice and simple explanation. if can you have information what is precise difference
    why interface is slow,why to use interface or abstract. What is need of two interface and abstract concepts in Java.

  293. Anonymous says:

    7.Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated,????????????

    HttpServlet is an abstract class;

    new HttpServlet(){};

    Servlet is an interface;

    new Socket(){
    implements all methods;
    };

  294. sou says:

    this is nice i want some more explanation with example for about interface and abstract class…….

  295. Venike ViswanathReddy says:

    this is nice sir but which one is pure abstract either interface nor abstract class

  296. Dharmendra says:

    in which condition abstract class failure but interfaces are used.

  297. Hari Krishna says:

    i want one answer related on interface?
    when one class can be implements an interface and as same class extends one another abstract class of this interface.?
    that is possible ?

  298. Hari Krishna says:

    //this is possible?plz give me ans.
    interface r1{
    void display();
    void add(int i,int j);
    int ram(int k);
    void ganesh(char c);
    }

    abstract class ram implements r1{

    ram() {
    System.out.println(“constructor is called”);
    }

    public abstract void ganesh(char c);

    public int ram(int k){
    return k;
    }

    public void display()
    {
    System.out.println(“i am here”);
    }

    public void add(int i,int j)
    {
    System.out.println(“i and j value is”+i +” “+j);
    }

    void display(int k)
    {
    System.out.println(“the value is”+k);
    }
    }

    class a implements r1 extends ram
    {
    public void ganesh() {
    System.out.println(“this is”);
    }
    }

    class i {
    public static void main(String args[])
    {
    a var=new a();
    a.display( );
    a.add(5,6);
    //var.display(5);
    System.out.println(a.ram(4));
    }
    }

  299. ashis says:

    differences between collection and collections in detail please explain this am not able to understand

  300. Anonymous says:

    Hi

    I want to know when can i prefer Abstract Class or Interface.

    ie When can i choose Abstract Class or Interface.

    Please explain somebody, because i have little bit confusion on that

    Kindly please explain some body effectivly…

  301. Manibharathi says:

    //Interface
    public interface interfaces {
    void multiply();
    }

    //AbstractClass
    public abstract class AbstractClass {
    abstract void add();
    void display(){
    System.out.println(“hello world”);
    }
    }
    //SuperClass
    public class superClass extends AbstractClass implements interfaces{

    @Override
    void add() {
    int a=10;int b=10;int c;
    c=a+b;
    System.out.println(“Addition=”+c);
    }
    void sub(){
    int a=10;int b=10;int c;
    c=a-b;
    System.out.println(“Subraction=”+c);
    }
    @Override
    //method implementation
    public void multiply() {
    int a=10;int b=10;int c;
    c=a*b;
    System.out.println(“Multiply=”+c);

    }

    }

    //SubClass

    public class subClass extends superClass {
    public static void main(String[] args) {
    subClass s=new subClass();
    s.add();
    // code reusability
    interfaces inter=new superClass();
    inter.multiply();
    }
    }

  302. Manibharathi says:

    differences between collection and collections in detail please explain this am not able to understand

    Answer:
    Collection is an Interface it will extends Iterable Interface.
    eg..methods(add,delete,remove…)
    Collections is a Class it will extends a
    Object class.
    eg..List,Set,Map,SortedMap,Comparator,Comparable…

  303. Manibharathi says:

    I want to know..In MultiThreading if I am using HashMap means is there any chance to occur DeadLocks?

  304. Manibharathi says:

    What is meant by ThreadPool?

  305. Manibharathi says:

    what is the use of abstract class? give some examples?

  306. Manibharathi says:

    which is the best way to increase the application perfomance?(Multithreading Application)

    1.Extending Thread.
    2.Implementing Runnable Interface.

  307. bharat patel says:

    why it is said that java provides more security than any other language?

  308. bharat patel says:

    why it is said that java provides more security than any other language?

  309. Rohit vasavda says:

    Thank

  310. swati gupta says:

    very well explained.

    Thanks

  311. Akhilesh says:

    Hi Joe,

    Thanks for the detailed articles…your site is very good for beginners as well as for experienced java programmers…

    About the interfaces and abstract class one thing always come to my mind that why do we need an abstract class? As if I write an abstract class with all abstract methods then there is no difference between interface and abstract class so why to have it?
    If given a chance to write an abstract class or an interface which one to choose?

  312. Jyothylakshmy.P.U says:

    Thank you..Outstanding discription.

  313. Jyothylakshmy.P.U says:

    Thanks.Outstanding discription.

  314. raju says:

    using System;

    namespace AbstractsANDInterfaces
    {
    ///

    /// Summary description for Employee.

    ///

    public abstract class Employee
    {
    //we can have fields and properties

    //in the Abstract class

    protected String id;
    protected String lname;
    protected String fname;

    //properties

    public abstract String ID
    {
    get;
    set;
    }

    public abstract String FirstName
    {
    get;
    set;
    }

    public abstract String LastName
    {
    get;
    set;
    }
    //completed methods

    public String Update()
    {
    return “Employee ” + id + ” ” +
    lname + ” ” + fname +
    ” updated”;
    }
    //completed methods

    public String Add()
    {
    return “Employee ” + id + ” ” +
    lname + ” ” + fname +
    ” added”;
    }
    //completed methods

    public String Delete()
    {
    return “Employee ” + id + ” ” +
    lname + ” ” + fname +
    ” deleted”;
    }
    //completed methods

    public String Search()
    {
    return “Employee ” + id + ” ” +
    lname + ” ” + fname +
    ” found”;
    }

    //abstract method that is different

    //from Fulltime and Contractor

    //therefore i keep it uncompleted and

    //let each implementation

    //complete it the way they calculate the wage.

    public abstract String CalculateWage();

    }
    }

  315. raju says:

    Feature

    Interface

    Abstract class

    Multiple inheritance

    A class may inherit several interfaces.

    A class may inherit only one abstract class.

    Default implementation

    An interface cannot provide any code, just the signature.

    An abstract class can provide complete, default code and/or just the details that have to be overridden.
    Access Modfiers An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public An abstract class can contain access modifiers for the subs, functions, properties

    Core VS Peripheral

    Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface.

    An abstract class defines the core identity of a class and there it is used for objects of the same type.

    Homogeneity

    If various implementations only share method signatures then it is better to use Interfaces.

    If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.

    Speed

    Requires more time to find the actual method in the corresponding classes.

    Fast

    Adding functionality (Versioning)

    If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method.

    If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.
    Fields and Constants No fields can be defined in interfaces An abstract class can have fields and constrants defined

  316. khan says:

    When to use Abstract and when to use Interface ?

  317. khan says:

    When to use Abstract and when to use Interface ?

  318. Revan says:

    Hi,

    Thankx for posting this article, but ,
    instead of posting what is there in books, you explain the main difference with an example. That may use for beginners who are reading this article.

  319. suresh says:

    Dear friend,
    could you please send your core java preparation kit.

  320. vicky says:

    sound great…..!

    Dear joe, you can also add particular program based on any topics for the
    demonstration ,so we can understand this better way.
    and u r site structure is inovatic.

  321. Puja Kumari says:

    Is it possible that an abstract class have no any abstract method?

  322. risit j patel says:

    thank you….
    its easy to understand…..

  323. risit j patel says:

    thnx ….
    its easy to understand…..

  324. suresh says:

    hai im newly learning java i have question. i.e is in below

    In Java, under what circumstances would you use abstract classes instead of interfaces? When you declare a method as abstract, can other nonabstract methods access it? In general, could you explain what abstract classes are and when you might use them?

  325. suresh says:

    Those are all excellent questions: the kind that everyone should ask as they begin to dig deeper into the Java language and object-oriented programming in general

    Yes, other nonabstract methods can access a method that you declare as abstract.

    But first, let’s look at when to use normal class definitions and when to use interfaces. Then I’ll tackle abstract classes.
    Class vs. interface

    Some say you should define all classes in terms of interfaces, but I think recommendation seems a bit extreme. I use interfaces when I see that something in my design will change frequently.

    For example, the Strategy pattern lets you swap new algorithms and processes into your program without altering the objects that use them. A media player might know how to play CDs, MP3s, and wav files. Of course, you don’t want to hardcode those playback algorithms into the player; that will make it difficult to add a new format like AVI. Furthermore, your code will be littered with useless case statements. And to add insult to injury, you will need to update those case statements each time you add a new algorithm. All in all, this is not a very object-oriented way to program.

    With the Strategy pattern, you can simply encapsulate the algorithm behind an object. If you do that, you can provide new media plug-ins at any time. Let’s call the plug-in class MediaStrategy. That object would have one method: playStream(Stream s). So to add a new algorithm, we simply extend our algorithm class. Now, when the program encounters the new media type, it simply delegates the playing of the stream to our media strategy. Of course, you’ll need some plumbing to properly instantiate the algorithm strategies you will need.

    This is an excellent place to use an interface. We’ve used the Strategy pattern, which clearly indicates a place in the design that will change. Thus, you should define the strategy as an interface. You should generally favor interfaces over inheritance when you want an object to have a certain type; in this case, MediaStrategy. Relying on inheritance for type identity is dangerous; it locks you into a particular inheritance hierarchy. Java doesn’t allow multiple inheritance, so you can’t extend something that gives you a useful implementation or more type identity.
    Interface vs. abstract class

    Choosing interfaces and abstract classes is not an either/or proposition. If you need to change your design, make it an interface. However, you may have abstract classes that provide some default behavior. Abstract classes are excellent candidates inside of application frameworks.

    Abstract classes let you define some behaviors; they force your subclasses to provide others. For example, if you have an application framework, an abstract class may provide default services such as event and message handling. Those services allow your application to plug in to your application framework. However, there is some application-specific functionality that only your application can perform. Such functionality might include startup and shutdown tasks, which are often application-dependent. So instead of trying to define that behavior itself, the abstract base class can declare abstract shutdown and startup methods. The base class knows that it needs those methods, but an abstract class lets your class admit that it doesn’t know how to perform those actions; it only knows that it must initiate the actions. When it is time to start up, the abstract class can call the startup method. When the base class calls this method, Java calls the method defined by the child class.

  326. priyanka says:

    page is developed very nicely… i liked it…

  327. please send whole book it is very nice

  328. Madhan says:

    Very nice. Thanks

  329. latha says:

    please send d complete buk for me

  330. Jayapal says:

    Hi All,

    Interface is also method It was implemented in class.But abstract class contain abstaract methods(I mean concrete methos)

    multiple interface is implemented with interface.But with abstract class its not possible.

    Interface contains all public static variable and methods.But in abstract class static variables,static blocks,concrete methoods

    defination of abstract class:
    class A{
    int sum(){
    }
    }
    abstract class B extends A{
    sum(){
    }

    }

    B is called abstract class because it should not override all the methods and parameters in super class A so it is called
    abstract class.

  331. Jayapal says:

    sorry multiple inheritance implementer with interface but with abstract class its not possible

  332. Venkat says:

    The explanation which is very transparant.

  333. Sajjan says:

    Pls Send me A Complete boook For java…

  334. pratap kumar rout says:

    plz explain with exampl.

  335. sandeep says:

    Joe u wrote that an interface can extend multiple interfaces but java does not support multiple inheritance so how this is possible ? please explain .

  336. Suncrack Oreocookie Gupta says:

    Hi, this is Harold Kumar Oreocookie Gupta, of the Gupta family in India.

    Can you write me example of the aforementioned article? Ideally with examples of the main concepts and differences given by your beloved article? I’ll be waiting for your examples and I’ll check back tomorrow afternoon precisely at 15:00.

    • Joe says:

      Harold,

      I don’t get you! You want an example for an interface and an abstract class, is it? Those are straight forward!

  337. Pawan Ydav says:

    why does java have both abstract class as well as interface? what is the need or importance of having both?

    • ashish says:

      Interface has incomplete implementation so that a user can do it himself as needed,it also forces the implementing class to write for the methodsw in interface,so that becomes a standard.While in case of abstract class the user can override the methods of superclass or can use the implementation written in that superclass …

  338. Sivakumar says:

    Hi Joe,

    Thanks a lot for your article posted. Could you please provide me an example program for interface and abstract classes better can understand?
    Thanks in advance for your reply.

    Regards,
    Sivakumar.

    • vivek says:

      java introduced interfaces for solving multiple inheritence (which it donot support) A class(particular class) can be a subclass of only one super class, but an interface can extend as many other interfaces as you want. Just list them after extends, separated by commas.

      public interface interfaceName extends superinterfaceName,superinterfaceName1,superinterfaceName2
      {
      interface body…
      }

      and coming to abstract class is a class which may or may not contain abstract methods but if does the child class which inherits it must do implementation for abstract methods
      abstract class A()
      {
      public void add();
      public void bark();
      }
      class B implements A
      {
      public int add()
      {
      //some code for addition;
      }
      public int bark()
      {
      //some code for bark;
      }

      }

      }
      note:class cannot implement an interface but it can extends the interface

      • saj says:

        ‘java introduced interfaces for solving multiple inheritence (which it donot support)’

        Believe Java guys had a reason for not supporting multiple inheritance by not allowing extending from multiple classes. What could be the reason for it. And if multiple inheritance was not desired, y did they allow implementation of multiple interfaces?

  339. Satheesh.C says:

    what is real time use of interface and abstract class..can u explain Joe?..I am waiting for your valuable reply

    thanks in advance

  340. vivek says:

    ur content is good but i think u must change background color caz its difficult see content wid hat brown back ground
    u can feel that tooo by watching content in blog and our comments bakground

  341. selvakumar says:

    We can add below,
    1,We can restrict the Method access outside of the class.If class A has 5 methods and Client A1 wants only 3 methods and Client B1 wants 2 methods then we can implement corresponding interfaces 1 has 3 methods and another has 2 methods and same will be used in client.
    2.We can generate Dynamic proxies using interfaces whereas its not possible in abstract class.

  342. Gayathri Chitnhala says:

    Which one is better in Inheritance and Interface?
    Please give me example also.

  343. Bhavesh says:

    1)we can compile and execute abstract class But Interface class only Compile not Execute …

    2)abstract class can extends only one class But Interface can extends Multiple interfaces
    Ex. interface C extends A,B
    But in Abstract class B extends A only..

  344. Mani says:

    When do use interface and abstract class in the following case when both looks the same?

    public interface TestInterface {

    void method1();
    void method2();
    }

    public abstract TestAbstract {
    void method1();
    void method2();
    }

    Please advise..

  345. Anonymous says:

    pls send some java material because i applied for ocjp

  346. Anonymous says:

    dude an abstract class can’t impalement Interface…………..i think u r wrong!!!!

  347. seshu says:

    nice,easy understandable

  348. vaibhav says:

    vary nice difference is easy understandable

  349. Ranjith says:

    can u give the real time example for the abstract class and interfaces

  350. Rajeswari says:

    Thanks, I have one doubt
    In one of the interview they asked like this
    any other use is there for Interfaces? other than Multiple Inheritance?

  351. Mit says:

    how we can implement security on web-site, which ve developed in java.

  352. suresh says:

    why java using class ,abstract class and interface

  353. suresh says:

    why we are using string args[] in main method header

  354. Ashish says:

    Please tell me different scenario for both interface and abstract class when can we use ?

  355. Raghu says:

    Sir,

    in what situation we have to use abstract class or interface .interfaces has only method declaration what is the use of it?

  356. amitesh says:

    some point is not true

  357. rajkumar says:

    An abstract class allows you to provide a default implementation for some of the methods but an interface does not allow you to provide any implementations.

    You can implement multiple interfaces but you can only inherit from one abstract class.

  358. Kiran says:

    when do we create interface instead of creating abstract class??

  359. jeevani says:

    Why we need to use interface?

  360. JItendra Trivedia says:

    Hey that’s a nice tutorial…..But i just want to know what is the real use of the interface except Multiple Inheritance……………Please I’m confused

  361. Manjinder singh says:

    According to me,,:

    An interface consists of abstract methods only and if we implement any interface into our concrete class we have to give the body of all the abstract functions of the interface,, but if i make a toString method in my concrete class which implementing an interface, the toString method is working efficiently, whereas there is no abstract method in the interface…..

    And if the toString method is coming from the object class then it must be coming with some other methods also, then why we haven’t given the body of all other functions in our concrete child class…

    Please correct me and guide me for this, its a humble request joe sir…

    thanking you in advance…

  362. Kamlesh says:

    This difference is syntactically which is not good
    You have to give difference by real time use .
    Suppose i make all method as abstract in abstract class and this method are also in interface then abstract and interface become same so why java found interface? Any body have Answer of my Question then please send me mail

    • Manjinder singh says:

      kamlesh , i think interfaces helps in achieving multiple inheritance, thus we need them too.

      hope this satisfy your question a lil bit.

  363. Arvind says:

    Hi Joe,

    I am big fan of your blog. several times, I got a big help from this for searching answers tuff FAQs of interviews…………

    I want to add one thing that this question is SUPER-HOT and EVERGREEN in any java interview……..but as per your another answers of another question on your blog ………….this answer is just childish……..So please post your response in a professional manner to understand the need and use of both the concepts into the root level.

    I want to understand properly about Abstract Classes and Interfaces that………..at which situation we generally use Abstract classes??????? and in which specific situation, we use Interfaces………?????? Would U please give explanatory response for this with real-time examples…………

  364. Noorul says:

    Hi,
    Can u write code for this point
    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.

    I tried but no result yet..

  365. Anonymous says:

    back ground is too worst please change the back ground as early as possible we could not find the words and letters.
    with regards,
    venkatesh.j

  366. jignesh says:

    thank you for this diffrence

  367. Rajesh says:

    hai sir, i hava one question.

    There is a list of countries.
    and each country has some number of products.

    To store these which collection class should I take.. and how would I store them.

    please reply with answer.

    thankyou sir.

    • Manish says:

      Go for HashMap, Country Name is your key and list of product your ArrayList.

      For Example,

      if Country India having
      list.add(“Prod1″)
      list.add(“Prod2″)
      list.add(“Prod3″)

      then,

      map.put(“India”, list);

    • Anonymous says:

      Its better to the apache commons collection class MultiValueMap there this can be done very relaible

  368. Gyanendra Singh says:

    Abstract class: some
    method
    implementations, some
    methods abstract
    (method definition
    only)

  369. Sathishkumar says:

    Change the font color or change the background. I feel it not readable.

  370. rakesh says:

    please relist your topics sequentially to make this tutorial even more valuable. And make the missing topic available. great tutorial by the way.

  371. Manish says:

    Thanks ! Well written article :)

  372. Aasif Abrar Khan says:

    i like 7 difference bcoz it contain logic,u show good difference.

    Thanks

  373. saravana guru says:

    in which situation we have to use interface and abstract class

  374. saravana guru says:

    which situation we have to use interface and abstract class

  375. Avinash says:

    Hi Joe, You have given a bookish points. Why don’t you tell us what is the use of interfaces or abstract class? Why do we need both of them, either of one is sufficient. Isn’t it? What are their individual importance?

  376. Anonymous says:

    “public void abstract class Employee” and “public void Employee(String name, String address, int number)” These two lines are wrong.. a class as well as a constructor cannot have any return type.

  377. Anonymous says:

    Does an interface provide almost all benefits of multiple inheritance which is not supported in java.?

  378. Anonymous says:

    why dont abstract methods have any implementations in an abstract class, but in subclass of the abstract class.?

  379. Mayur says:

    Interface couldn’t be implemented by any other Interface…..

  380. goutamreddy says:

    can u give me the difference between abstract class and interfaces

  381. Java Development Training says:

    It is an error to specify the static modifier for the abstract method.

  382. rakesh says:

    suppose there is only a one abstract method we have in a abstract class and in a interface…….which of them will be more benificial to implement or extend,a abstract class or a interface??///and why??? please tell

  383. Anonymous says:

    In what scenario we use abstract class and interface ??

  384. himanshu sharma says:

    in what scenario we use abstract class and interface ?

  385. [...] functionalities. Till now we have got an interface and an implementation concrete class. Create an abstract class that contains (aggregation relationship) an attribute type of the interface. The constructor of [...]

  386. Nitin Agrawal says:

    One more difference.
    Interface never participate in object creation while abstract class object is created with a child class object. Though developer can not create instance of abstract class by using new operator.

    Moreover, Interface are not used for multiple inheritance (What will you inherit from interface. It has nothing to be inherited).

    Interface are used in specifications like JDBC.

    Interface are used in remote accessebility (RMI). You can have 2 interfaces for one service. If you are providing one interface to client, he will not be able to call the methods defined in second interface.

  387. Anand says:

    can interface extends class?

  388. Anonymous says:

    va

  389. Debojit says:

    These differences are mostly syntactical and very specific to java. i found the most astounding differences:
    Interface is the peripheral identity of a class
    Abstract class is the central identity of a concrete class. You actually should not differentiate these two, however these two manifest the most powerful aspects of OOP

  390. Atikur Khan says:

    Can any one explain:-

    1.Why connection,resultset and statement are interfaces?

    2.When above are interfaces then how can we call their functions as they don’t have method implementation(By Interface definition).

  391. Kumar Bhatia says:

    Introduced new blog on java.
    javacodeimpl.blogspot.com

    Keep visiting!!!

  392. by using Abstract class u cont extends multible inhertence,but by using interface we can achive multible inheritence says:

    by using Abstract class u cont extends multible inhertence,but by using interface we can achive multible inheritence

  393. shivani says:

    abstract classes can contain constructor

  394. shiv says:

    public abstract class AbstratctClassTest {
    public AbstratctClassTest(String str){
    System.out.println(“AbstratctClassTest is calling “+str);
    }

    public static void main(String str[]){
    Abst obj=new Abst(“hi”);
    obj.sayHello();
    }
    }

    class Abst extends AbstratctClassTest
    {
    public Abst(String str){
    super(str);
    System.out.println(“in abst constructore”);
    }
    void sayHello(){
    System.out.println(“Hello…”);
    }
    }

  395. Nice Blog!! The info will be very useful for a beginner in the java programming.

  396. Kapil says:

    As I understand one more difference:

    Interface describes ability of the class.
    Abstract class describes identity of the class.
    Therefore you can have many abilities but just one identity.

    Please add this to your post if found appropriate.

  397. sana says:

    can anyone tell me in which situation one can use abstract class and one can use interface????

    • raju says:

      if we dont know anything(for example:zero percentage) about implementation go for INTERFACE
      if we know something(for example:roughly 30 to 40 % percentage) about implementation go for abstract class as an abstract class can contain both defined(implemented) and undefined(abstract or unimplemented )methods
      if we know every thing(for example 100% not exactly but almost) about implementation then go for conrrete class that is class

      • Hi Raju,

        Then why we will use interface according to your answer. if we know more less than then also its better to go directly abstract classes. Then why this interface came to market. Can you please explain me this?

        Thanks & Regards
        Sailendra Narayan Jena

  398. vipesh says:

    please tell me what is the use of interface,when we can instead of interface can we use abstract class contain only abstract method(pure abstract class)

  399. vel murugan says:

    Scientific calculation using event driven programmi ng…
    i need this program,,plz send me soon..

  400. Gat Yogesh says:

    hi,
    The interfaces are not default final because it can be extended
    final class can not be sub-classed.

  401. Nayaz says:

    why do we actually need interface???when abstract class only can do what ever the things done by interface?apart from multiple inheritance?

  402. Anonymous says:

    Really your blog superb to learn about java

  403. Anonymous says:

    Really your blog is superb for learning java..

  404. Hi,

    I want to know the exact difference means in which scenarios we will use abstract class and in which scenarios we will use interface.

    My another question on this topic is:
    1. We know that we can’t create object for both interface and abstract class but can you tell me as you have mentioned there in case of main method how we will create the object for the abstract class with examples?

    2. In case of project scenarios if we are creating interface then what is the need for this interface in future cases, which class implements that interface and if we will add some new method inside this interface in future then also it will reflect to all those classes where its got implements. So can you please explain me?

    Thanks & Regards
    Sailendra Narayan Jena

  405. anupriya says:

    what is extra indirection….you have mentioned in the 8 point….plzz explain

  406. rakesh says:

    hi joe!…your every article is very admirable…Can u please explain 8th point

  407. naisargee says:

    thankyou sir , it helped me a lot!!!

  408. Govind Agrawal says:

    //* Program of implement the interface Keyword *//

    interface A
    {
    void sum();
    }
    class B implements A
    {
    public void sum()
    {
    int a=12,b=3,c;
    c=a+b;
    System.out.println(“Sum of the number =”+c);
    }
    }
    class Result
    {
    public static void main(String as[])
    {
    B s1=new B();
    s1.sum();
    }
    }

  409. sachin says:

    what is the real time difference between abstract and interface?
    Like When are you going to use abstract and interface in real time project development.

  410. Karthika says:

    I m totally confused. Can u explain me the difference between abstract class and interface

  411. Anonymous says:

    Really good stuff……

  412. Anonymous says:

    very good

  413. Sharma Amit says:

    Very nice sir … thanks a lot for sharing your knowledge with us…..

  414. Anonymous says:

    very nice

  415. Anonymous says:

    Nice Info.
    BTW if someone wants to read little bit about abstract classes check out this link then http://javaandme.com/core-java/abstract-classes
    I found it usefull, hope it will help you guys also.

  416. Payel Hazra says:

    Hi, the 5th point says that an interface can extend another interface only, but actually an interface can extend multiple interfaces. Correct me if I am wrong.

  417. Srikantareddy A says:

    hi joe,
    5th point is wrong, i.e an interface can extend any number of interfaces

  418. Sabyasachi says:

    Nice example and very helpful Sir.
    Example of Interface extends and implements:

    public interface Interface3 {
    public void test3();
    public void gett3();
    }

    public interface Interface2 extends Interface3{
    public void test2();
    public void gett2();
    }

    public interface Interface1 extends Interface2, Interface3 {
    public void test1();
    public String gett1();
    }

    //——- Now in class, implements the Interface(s).
    public class InterTest implements Interface1{
    // implement all unimplemented methods.
    }

    or

    public class InterTest implements Interface2, Interface3, Interface1{
    // implement all unimplemented methods.
    }

    Thanks

  419. Anonymous says:

    Thanks really good stuff.

  420. Gopal Gowda says:

    Hi Joe,

    What is the decision point I should be making when choosing interface or an abstract class? This is one question I don’t find proper answer and I always end up seeing the difference b/w them on the net.

    Thanks in Advance.

Leave a Reply