If my class implements
an interface then can I say that I'm following inheritance? I know that when a class extends
another class then it's inheritance.
Java Interfaces – Is Implementing an Interface Called Inheritance?
definitioninheritanceinterfacesjavaterminology
Best Answer
UPDATE: I've revised this answer. A number of good points were raised in the comments that deserved calling out.
It is not entirely clear what you mean by "following inheritance". Let's ask a slightly different question?
These are subtly different. That is unfortunate because it is confusing.
Confusion may arise because people think of inheritance as a mechanism for sharing implementation details. Though it is such a mechanism, that mechanism works by sharing members. Those members need not have implementations! As we will see, they can be abstract.
I personally would be happier if the Java and C# specifications used a word other than "inherits" to describe the relationship between interface methods and classes, to avoid this confusion. But they do not, and we have to reason from the specifications, not against them.
Yes, some are. See the Java specification section 8.4.8, which I quote here for your convenience.
If you say that a class implements an interface then the class inherits the abstract and default methods of that interface. (Of course I have omitted the conditions which follow; see the specification for details. In particular, a class which implements a member of an interface is not considered to have inherited that member. Again, is this confusing? Yes.)
Typically we would say that a class implements an interface. As noted above, a class may inherit members from an interface, and yet still not be said to inherit from the interface. Which is confusing, yes.
Typically not. This sort of narrow parsing of the specification is more useful to compiler writers than line of business developers. Its more important to understand when to use an interface than it is to get a precise definition of "inherits from".