What is the "real" meaning of the key word 'extends' in Java?

Asked

Viewed 219 times

3

First of all, I know how to use and work the keyword extends, my real doubt lies in the meaning of that word, more precisely because extends and not inherit or something like that? The only thing that comes to mind with this word is that the scope of the current subclass "extends" to that of the superclass, and yet, why?

  • Who created the language decided so ? (just a pitaco, I don’t really know)

  • 1

    I know it has some meaning beyond, as well as the meaning of classes (that few people know), but I can’t remember

  • 2

    In the [Oracle glossary][1]:extends- The Term is used in a class declaration to specify the superclass. In an interface statement it is used to specify one or more superinterfaces. Class X extends class Y to add functionality, either by including fields or methods to class Y or by overriding methods from class Y. A Z interface extends one or more interfaces by adding methods. Class X is considered a subclass of class Y. The Z interface is considered to be a subinterface of the interfaces it extends.

1 answer

2


These things you can never affirm with certainty unless you have a document that says why this choice was made, which I don’t know exists.

Most likely by this choice is that the most correct semantics is to extend that class, which is different from implementing an interface and that both are making an inheritance, so if you used inherits It would define poorly what is that, which is even an inheritance, but has something else that is inheritance as well (taxonomy allows having more than one name for something that has different levels of observation), so it made more sense that way. At least the choice has a logic.

One interface extends another interface. Interestingly in new versions it is possible to extend an interface, although the term remains the same, it would not make sense in some cases to use a word and and others to use another term, it is better to accept that it is not always the best term, languages are not languages. It’s not always easy to do the right thing.

Some people criticize C# who uses : for everything, but at least it is not a word that gives a more specific meaning.

  • I thought I deserved a mention of extends for interface. Although it is the same character set, the semantics, for me, is quite distinct

  • Do you think? Because it really extends somehow to another. It’s not exactly the same.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.