views:

77

answers:

1

Quick question. Does a class have to implement a interface directly to be accepted, or can it be a child of a parent class that implements it.

so If I pass a child object into a method that only accepts IOBJECT, but the child class parent implements IOBJECT. will child object be accepted ?

+8  A: 

If the parent satisfies IS-A for an interface type the child does as well. The child need not implement the interface.

duffymo
I am not formiluar with the term IS-A, but I think I get what your saying.
numerical25
a Parrot IS-A Bird and a Bird IS-A Animal... So if you implement an interface method in Animal, with accessibility set to anything other than private, then both Bird objects and Parrot Objects have access to that method, so they also implement the interface.
Charles Bretana
@numerical25 - IS-A means "inheritance" that satisfies the Liskov substitution principle; HAS-A means "composition".
duffymo
Methods in interfaces are always public, as far as I know. Bird and Parrot objects will either call the method as implemented by their parent Animal or override it with their own behavior.
duffymo