Interview Question

Lead Technical Architect Interview

-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.

AnswerAdd Tags

Interview Answers

4 Answers

1

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.

Anonymous on

0

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! on

1

You would be using the Adapter Design Pattern.

Arrrgh on

1

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 on

Add Answers or Comments

To comment on this, Sign In or Sign Up.