0

What is the difference between interfaces (implements) and inheritance (extends)?

12th Apr 2017, 12:59 PM
Green
2 Respostas
+ 3
implementing a interface is like implementing a contract between your class and the interface so if you want these contract to be approved then you need to override all methods of the interface otherwise this contract can not be approved.. Some properties of a interface: 1.you can't create a object of a interface 2.an interface doesn't have a constructor etc. Abstract Classes An abstract class is a class that contains the abstract keyword in its declaration Here you can implement the methods if you need but is not mandatory. Some properties of a Abstract class 1.has abstract methods(without body) 2.you can not create an object of a abstract class etc. So you can only extend one abstract class but you can implement as many interfaces as you want just separating them with a comma (,).
12th Apr 2017, 1:12 PM
( ͡° ͜ʖ ͡°)
+ 1
Inheritance is a way for the objects in your program to have the attributes and behavior of a superclass, so the number of subclasses, sub-subclasses, etc. can extend indefinitely. Implementation is closer to making a template for other classes to rigidly follow - if an interface has a method, the class that implements said interface MUST have that method in it, whereas subclasses can omit methods they don't use.
12th Apr 2017, 1:09 PM
DaemonThread
DaemonThread - avatar