+ 3

How's Interface distinct from class and abstract?

23rd Apr 2017, 2:07 PM
John Watson
John Watson - avatar
2 Respuestas
+ 3
For Java: == Class == - when inheriting from a superclass you can re-implement (override) or not certain methods from the superclass; it's up to you - you can only directly inherit from ONE superclass == Interface == - all method from the interface HAVE TO be implemented by the inheriting class. It's like a contract. - all methods are abstract, i.e. empty. The inheriting class has to implement it - you can inherit from multiple interfaces == abstract classes == - abstract class can but must not contain abstract method. They can contain abstract method but along with it also fully implemented methods - abstract classes are faster than interfaces
23rd Apr 2017, 3:23 PM
Thanh Le
Thanh Le - avatar
+ 1
Interface tell you "Your new class must have this methods" Abstract class tell you "Your new class must have this methods and also have this predefined behaviour", then are more complete than an interface. They cause more overhead also.
23rd Apr 2017, 2:17 PM
⏩▶Clau◀⏪
⏩▶Clau◀⏪ - avatar