ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Does Java support multiple inheritance?

user-image
تم إضافة السؤال من قبل ahmad yassine , Business Development & Performance , Boubyan Bank
تاريخ النشر: 2013/12/18
Cedric Nabaa
من قبل Cedric Nabaa , Java developer , Capital Banking Solutions

Strictly speaking java does not support multiple inheritance. One java class can only extends one class only. nevertheless you can implement as many interfaces as you wish. If you have a special case where you need to use multiple extends this means tahat your model is not solid enough. If you need any help let me know

Sandhya Binoy
من قبل Sandhya Binoy , Software Professional , Karrox technologies

Java does not support multiple inheritance.But Java support multiple interface inheritance.

An interface is a blueprint of a class.If a class implements multiple interfaces or an inteface extends multiple interfaces known as multiple interface inheritance.

Simple Eg:

public interface A

{

public String a='A";

}

public interface B

{

public String b="B";

}

public interface C

{

public String c="C";

}

public class D implements A,B,C

{

public static void main(String[] args)

{

String v1=a;

String v2=b;

String v3=c;

System.out.println("Variable a:" +v1);

System.out.println("Variable b:" +v2);

System.out.println("Variable c:" +v3);

}

}

 

mohammad rashid
من قبل mohammad rashid , Freelance Contractor , Freelance Contractor

NO.

 

The reasons for omitting multiple inheritance from the Java language mostly stem from the "simple, object oriented, and familiar" goal. As a simple language, Java's creators wanted a language that most developers could grasp without extensive training. To that end, they worked to make the language as similar to C++ as possible (familiar) without carrying over C++'s unnecessary complexity (simple).

In the designers' opinion, multiple inheritance causes more problems and confusion than it solves. So they cut multiple inheritance from the language (just as they cut operator overloading). The designers' extensive C++ experience taught them that multiple inheritance just wasn't worth the headache.

 

Instead, Java's designers chose to allow multiple interface inheritance through the use of interfaces, an idea borrowed from Objective C's protocols. Multiple interface inheritance allows an object to inherit many different method signatures with the caveat that the inheriting object must implement those inherited methods.

Multiple interface inheritance still allows an object to inherit methods and to behave polymorphically on those methods. The inheriting object just doesn't get an implementation free ride.

 

http://www.javaworld.com/article/2077394/core-java/why-not-multiple-inheritance.html

Manish Gour
من قبل Manish Gour

More technically speaking java doesnt support multiple inheritance coz is more thre ther two object are present at same priority then this would become a state of ambiguity for jvm to select which one of them ,if they have comman data ,and interfaces also seem to be implementing multiple inheritance but they are not following multiple inheritance in any way,

مستخدم محذوف‎
من قبل مستخدم محذوف‎

Ok boss you had listen that java doesn't support multiple inheritence according to classes.but  where as interfaces provides the multiple inherience.where as for a class you can implement only one class.where as interfaces can inherit more than one interfaces.

Ahmad Nauman
من قبل Ahmad Nauman , Assistant Director (IT Hardware) , Overseas Pakistanis Commission Punjab

Whenever you find yourself asking why Java has or does not have some feature, consider the design goals behind the Java language.

The reasons for omitting multiple inheritance from the Java language mostly stem from the "simple, object oriented, and familiar" goal.

Kamal Hasija
من قبل Kamal Hasija , Web Developer , The Brihaspati Infotech Pvt. Ltd.

hey java doesn't support multiple inheritence in real.but you can done it by extends/implements the interface that can help to get multiple inheritence.this is the reason why this feature is more strong in terms of core java.

No  java does not support the multiple inheritance Bcoz different classes may have different variable with same name that may be contradicted and can cause confusion.

Using interface , we access the multiple inheritance in java.

المزيد من الأسئلة المماثلة