Subhransu Mishra
Subhransu Mishra

Reputation: 3061

explicitly behave as an interface

can we make any class to behave as interface and so that we can write "implements" in place of "extends" while creating any child class of that class .what is the actual difference between "implements" and "extends" internally .

Upvotes: 0

Views: 79

Answers (2)

Thilo
Thilo

Reputation: 262534

I don't understand the question.

The Java language specification makes it clear that you can only extend classes and implement interfaces.

You could argue that you may want to use just the method headers of a class as an interface and implement that part (without inheriting the implementations), but you cannot do that with Java.

what is the actual difference between "implements" and "extends" internally .

Implements registers an interface, extends registers a parent class.

Upvotes: -1

Sagar V
Sagar V

Reputation: 1926

An interface is like a blueprint. It doesn't define any behavior. Hence when you say extends in the context of an interface it means you are extending the blueprint but not adding behavior. Conversely, when you say extends in the context of a class it means you are adding/modifying the behavior. When you say implements it means you are going to provide something that has behavior i.e. a class

Upvotes: 3

Related Questions