Quiz

 

Synergy/DE pros, see if you can answer this question!

Synergy .NET supports classes that implement interfaces, which provides a mechanism for a form of multiple inheritance. Consider the following scenario:

- An interface named Motion contains a property named "sprung".
- A class named Season also contains a property named "sprung".
- A second class, named Spring, extends Season and implements Motion. It does not override "sprung."

Which property implementation gets accessed for an instance of Spring?

a. Season.sprung
b. Motion.sprung
c. neither
d. both

Discussion:

One of the difficulties with multiple inheritance is the ambiguity that arises when two or more parent classes provide the same member. All languages that provide multiple inheritance also provide some rule for resolving the conflict or a means to explicitly select the desired behavior. Nevertheless, developers often experience confusion because they may be aware of only one of the candidates (usually the road not taken).

Synergy/DE, like C# and Java, does not provide true multiple inheritance. Interfaces (which are available only on Synergy .NET) provide some of the features that multiple inheritance was designed for — especially the ability to declare shared characteristics of otherwise disparate classes.

But interfaces avoid the problem described above by means of the rule that an interface cannot provide an implementation of the members it describes. An interface is implicitly abstract, as are all of its members. Therefore, there can only ever be one line of implementation inheritance: the class itself and its superclasses. In fact, one of those must provide each member described in the interface.

Thus, the correct answer is (a). You could argue that the one member is both Season.sprung and Motion.sprung (answer (d)), but we included the word "implementation" in our question, and the interface cannot provide an implementation.