Sollicitatiegesprek voor de functie Lead Technical Architect

-Phoenix, AZ

American Express

How you inherit the properties of two classes (not interfaces) in a child Java class. Where as those two parent classes are not related and not of any inheritance relationship between them.


Antwoorden op sollicitatievragen

4 antwoorden


My answer is, unlike other OO languages like C++ multiple inheritance is not possible in Java, and interfaces can be used to achieve this with specific implementation. The interviewer is not convinced with this.

Anoniem op


The answer is composition inheritance. It's not as convenient as implementation inheritance (extends keyword) but creating an instance of the parent object and making the child manage/expose necessary members. Probably be a good idea to create an interface to keep things.

Duh! op


You would be using the Adapter Design Pattern.

Arrrgh op


Inheritance is not possible this way but one can simulate the properties inheritance if the child class is in the same package as the 2 parent classes. If the 2 parent classes are themselves in 2 different packages this kind of inheritance simulation is not possible as protected members cannot be accessed by non-child classes.

rajan op

Voeg antwoorden of opmerkingen toe

Meld u aan of registreer u om hier een opmerking over te maken.