Is there any connection between the class that implements the interface and this interface?

Consider this class hierarchy:

  • Book extends Goods
  • Book implements Taxable

As you know, there is a relationship between a subclass and its superclass (is-a).

Q: Is there any "is-a" relationship between Book and Taxable ?

GOOD answers, but you said that "is-a" is also the relationship between Book and Taxable , but "is-a" is the relationship between classes and the interface is not a class!

+4
java interface class-hierarchy
source share
8 answers

Yes. The connection is exactly the same

The book is also taxed.

EDIT

An interface is an artifact that matches a Java (and possibly C #, I don't know) match interface .

The OO interface has many operations performed by the class, and nothing more. It is like a contract between an object class and its clients.

OO programming languages ​​that do not have the interface keyword still have the concept of an OO class interface.

+8
source share

Well there is "supports-the-operations-of". Personally, I do not find the mnemonics "is-a", "can-do", etc. Awfully helpful. I prefer to think in terms of what types allow, regardless of whether they specialize in existing behavior or implement the behavior themselves. Analogies, such as abstractions, tend to be leaky. If you know the differences between interface inheritance and implementation inheritance, you probably don't need extra phraseology to express this.

+5
source share

"Behave like..."

Whatever I say. Not something, but behaves somehow. Or as an alternative to “maybe something,” but more specific than behavior.

+3
source share

the relation will be as follows: 'implements'

these spring relationship names are from use in sentences. A “book” is a “Goods” that can be written without quotation marks and hyphens, and that makes sense. Similarly, “Instruments” “Taxes” can be written without quotation marks.

+3
source share

When we say that one class extends another class, it has a strong relationship, known as “inheritance”. This means that when one child expands the parent, then the child must be able to inherit something from the parent class, for example, the IS horse. Animal. some properties of animals. But when the class implements another class, then the child class tries to execute the contract, so you do not need to inherit anything from the parent, just following the contract, therefore the interface by all methods is abstract by default, but you can provide some specific method in the class (for the child class for inheritance) and can make some of then abstract good.

So for me extends this is inheritance and the interface when implementing contract.hope is satisfactory

+2
source share

This should do:

 public static boolean implementsInterface(Object object, Class interf){ return interf.isInstance(object); } 

For example,

  java.io.Serializable.class.isInstance("a test string") 

is true.

from: Check if an object implements an interface

+1
source share

What is all the excitement? A few question marks and a few exclamation marks?

Does it bother you that we can say that the book is taxable, although Taxable is an interface? Please calm down.

The language has different keywords for the relationship of the class to the interface and to the superclass, but the conceptual nature of these relations is the same, so it is quite reasonable to use the same English terms to describe it. A book is taxed, just like a book is good. To approximate the terms, the book is TaxableItem. This is normal.

+1
source share
 Book implements Taxable 

Here also the connection between Book and Taxable is

The book is "taxable"

Refer to this question . You can see what he says

When we talk about inheritance, the most commonly used keyword is extends and implements . These words determine whether one IS-A object will be another.

0
source share

All Articles