Sileria Inc. Interview Question for Software Engineer / Developers


Team: Android Application Development
Country: Pakistan
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

multiple inheritances does complicate the design and creates problem during casting, constructor chaining etc and given that there are not many scenario on which you need multiple inheritance its wise decision to omit it for the sake of simplicity. Also java avoids this ambiguity by supporting single inheritance with interfaces. Since interface only have method declaration and doesn't provide any implementation there will only be just one implementation of specific method hence there would not be any ambiguity.

So, we can support multiple inheritance in java using interfaces.

- Anonymous November 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I agree with you. Very important and precise reason that we can mention is the diamond problem which occurs in multiple inheritance. For example. Class B and C both inherits class A. And class D inherits both, B and C. So now this is a diamond problem as how will you decide which route will the class D get the heritage, i.e A-->B--D or A--->C-->D? Also a question arises will there be multiple copies of a class A public local variable in class D ?

- engr.fas November 29, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I wouldn't necessarily say it's a wise decision to exclude multiple inheritance. That depends on perspective. But yes, Java in particular omitted it for simplicity and to avoid a number of problems associated with it.

- Anonymous November 30, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

dimond problem can be handled through virtual inheritance and carefully design. If you do not need member variables from multiple classes, then you should not apply multi-inheritance.
actually, dimond problem is one of the advantages of multi-inheritance, how will you do in Java if D needs both properties in B and C ?

- Anonymous December 02, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nothing is impossible in Java. Java is written to program in a beautiful and smart way. As you mentioned above, it will be a design fault if D needs something like that. B and C both extending from A means Generalization to specialization and then you are making D to extend both which doesn't really look like a smart thing to do though I agree that there can be cases when you need to do so. But in order to solve that, I will rather use interfaces, or Make an abstract class and make A extend that class for example. It depends, there can be many design solutions for that in Java. Which we can come up with rather than creating the Diamond lock and confusing class C.

- Fahad December 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

"Nothing is impossible in Java."

Alas, plenty of things are, in fact, impossible in Java, such as placing things at specific memory addresses, etc.

It's not a design fault if D needs something like that. It's a language fault for not giving programmers something they need. There's nothing inherently wrong with wanting to inherit from two types. It was removed because it caused difficulties in C++ and was used somewhat rarely anyway.

- eugene.yarovoi December 12, 2011 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Apart from the above mentioned complications, there is one more danger. i.e one addition of class as parent at top of hierarchy can easily bloat the size of objects at child level. This is one reason why embedded systems (like Symbian) allways try to put restriction on multiple inheritance.

- Somisetty November 29, 2011 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More