Java abstract class and interface -


in interview have been asked following question. tried answer question want exact answer of question.

if can simulate abstract class interface, why java provided interface?

this mean if in abstract class can mark methods abstract , abstract class work interface, why need interface.

can explain me in brief.

that's standard interview question. answer is: because can implement multiple interfaces, can't extend multiple abstract classes.

example jre: linkedlist both list , deque. these interfaces define behaviour of class. not provide implementation details. while abstract classes could provide some.

related questions: this , this. latter not directly related, shows why interfaces needed, in cases when abstract class suffice.


Comments

Popular posts from this blog

Javascript line number mapping -

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -