Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

With the ability to add static methods and default implementations to an interface, what is now the practical difference between that and an abstract class?


- A class can only inherit from one abstract class, but can implement multiple interfaces.

- An interface cannot have member variables.


Also, an abstract class can have a constructor (and instance initializers, and initialization expressions for its fields), which an interface can't. That means an abstract class can do work when it is created.

Although it's probably a good idea not to do too much work - a factory method would be better for that.


Did you read the article? Try again, search for "Why abstract classes can't be instantiated using a lambda".


Interfaces with the addition of default methods, in contrast to abstract classes, provide the inheritance of behaviour (but not state) from multiple sources.


multiple inheritance?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: