Interview Question for Software Engineer / Developers






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

Multiple inheritance means subclassing from multiple classes.
Java doesn't support it for simplicity.
For example,
Class A
{
int a;
}
Class B
{
int a;
}
now as both the classes have variable a if class C inherits from both of them it makes it unnecessarily complex and you need to determine variable a of which class.
You can implement something similar to multiple inheritance using interface.

- Apal January 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

With reference to the above example,
make class B extend class A and class C extend class B.
Then class C will inherit from both class A and class B.

- badalrocks February 01, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Multiple inheritance means >>>
extends class plus implements interface

- Anonymous February 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Multiple inheritance in Java is possible using interfaces. Diamond problem is the main reason for not having multiple inheritance thro classes in Java.

- Raghu March 05, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Multiple inheritance in Java is possible using interfaces. Diamond problem is the main reason for not having multiple inheritance thro classes in Java.

- Raghu March 05, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

raghu rightly mentioned that Java avoids multi-inherit because of the inFamous diamond problem...

- Anonymous July 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

as mentioned in the above example... Java don't have it since it want to avoid ambiguity ( Diamond formation problem ).

Give two fixed class having common variable or implementation. You can achieve multiple inheritance by using composition of one class and inheritance of other.

choice depends on which class has more methods to delegate. that becomes inheritance base class.

- master January 01, 2010 | 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