What's the difference between the implements & extends keywords in Java [duplicate]
Asked Answered
C

2

23

What's the difference between the following keywords in Java: implements, extends?

Corroboration answered 29/2, 2012 at 6:13 Comment(0)
P
39

An interface is an abstract specification of how a class should behave whilst a class is a concrete implementation of such a specification.

Therefore, when you write implements you're saying that you are fulfilling some abstract specification in the implementation you've written.

extends means that you take either an implementation (class) or specification (interface) and add to it with different or new functionality (or change the specification of its behaviour), thus modifying its behaviour and extend-ing it.

Precarious answered 29/2, 2012 at 6:19 Comment(0)
D
12

a class extends another class and implements interface. interface extends another interface.
Interface hasn't any implemented methods all defined methods are empty so if class inherits from the interface it should implement it's methods. But if Class1 inherits from Class2 then it already have some working methods (from Class2) and just extends Class2.

Dashing answered 29/2, 2012 at 6:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.