0

Why we have both Interface and abstract class, even we can achieve interface by making all methods of abstract class abstract. Please explain the usage difference between both.

  1. List list = new ArrayList();

  2. ArrayList arraylist = new ArrayList();

what difference the above two lines make, except dynamic method dispatch. Rather if we define with ArrayList reference we can have more methods to use.

Thanks in Advance. :)

  • 3
    Because abstract classes can have state, which interfaces cannot. – fge Jul 30 '16 at 22:48
  • But we can make abstract class state-less, then is it interface became useless implementation by java? – Sudip Prasad Jul 30 '16 at 23:09
  • I think you're talking about Liskov's Substitution Principal, which in short means that what is important isn't "ArrayList" or "LinkedList" as much as "This is a List, please treat it as such". It allows you to decide to change underlying implementations at a later time without breaking child dependencies. – Rogue Jul 30 '16 at 23:50
  • @Rogue - Thanks a lot, now got it what is the use. – Sudip Prasad Aug 01 '16 at 17:18

0 Answers0