Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners multiple inheritance
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


nisar
multiple inheritance
3 Answer(s)      4 years and 3 months ago
Posted in : Java Beginners


Why java does not support Multiple Inheritance?

Advertisement
View Answers

July 6, 2010 at 10:40 AM


First of all the question is wrong the correct one is.........

Q)why java classes does not support Multiple Inheritance?

JAVA CLASSES ONLY NOT SUPPORT MULTIPLE INHERITANCE.But Java Interfaces can support Multiple Inheritance.

Ans...>java classes doesn't support multiple inheritance,the practical reason is there


public class superclass1
{
int a,b;
public void m1()
{
.....
....
}

}

public class superclass2
{
int a,b;
public void m1()
{
.....
....
}

}

public class subclass extends superclass1,superclass2
{

........... here we are getting the ambiguity to extends the
.......... methods and variables.Because here we are using the same
........... user defined methods in both super classes.When we
............ are extends the both super classes [ superclass1 and
.......... superclass2 ] , getting the confusion.Because in both super classes are have same user defined methods.

}
That's why java classes does not support multiple inheritance.But java interfaces supports multiple inheritance.Because interface doesn't contain concrete methods, it contain only abstract methods.So there is no problem to use multiple inheritacne in this case.


July 6, 2010 at 12:26 PM


Hi Friend,

When we extends more than one class, JVM get confused as to which method it should call. This causes complexity and inconsistency. So to avoid these
complexities and inconsistencies Java does not support Multiple Inheritance.

Thanks



August 22, 2011 at 3:23 PM


Let be specific. Java Does NOT support - multiple IMPLEMENTATION Inheritance, but but wait JAVA SUPPORTS MULTIPLE INTERFACE INHERITANCE How? One of the way it can do is using the Adapter pattern.

e.g. consider and Employee class which needs to extend 2 concrete classes say Person and Employment So guys lets do it this upfront now create 2 interfaces viz. 1. PersonLike* which will be implemented by the concrete class Person and 2. EmployeeLike* which will be implemented by the concrete class Employment

Suppose the PersonLike interface is:

public interface PersonLike {
String getName();
int getAge();
} 
and the EmployeeLike interface is: 

public interface EmployeeLike {
float getSalary();
java.util.Date getHireDate();
} 


Here is how our Employee class which needs to extend 2 concrete classes say Person and Employment as below


public class **Employee** extends **Person** implements PersonLike, **EmployeeLike** { 
  private EmployeeLike employment = new
  Employment();
  public float getSalary() { return
  employment.getSalary(); }
  public java.util.Date getHireDate() { return   
  employment.getHireDate(); }
 }
}

As in the above example we have extended Person, so there is no need for the implementation, but for Employment to be extended we create a variable(employment) of type EmployeeLike. This variable will then be used to implement the Interface methods for the interface EmployeeLike.

Hope I am clear.

I got this cleared using the below link



Related Tutorials/Questions & Answers:
multiple inheritance.
multiple inheritance.  hello, can java support multiple inheritance???   hi, java does not support multiple inheritance
multiple inheritance
multiple inheritance  why java doesn't support multiple inheritance? we can achieve this by using interface but not with classes? what is the main reason that java community implemented like
Advertisements
Multiple Inheritance
class so java any how do multiple inheritance? Can you please explain...Multiple Inheritance  All are saying java doesn't support multiple inheritance but by default Object class is super class for all the user defined
Multiple Inheritance
Multiple Inheritance  Why Java Doesn't have Multiple Inheritance It is Advantage or Disadvantage.........   Hi Friend, When we extends... and inconsistencies Java does not support Multiple Inheritance. Thanks
multiple inheritance
multiple inheritance  Class A extends Class B but Class A also inherit Super Class Object so it is multiple inheritence give reason in support of your answer
multiple inheritance - Java Beginners
multiple inheritance  Why java does not support Multiple Inheritance...)why java classes does not support Multiple Inheritance? JAVA CLASSES ONLY... Inheritance. Ans...>java classes doesn't support multiple inheritance,the practical
multiple inheritance - Java Beginners
multiple inheritance  can u implement one class to more than one interface
Does Java support multiple inheritance?
Does Java support multiple inheritance?  Hi, Does Java support multiple inheritance? thanks   hi, Please visit the following link: http://www.roseindia.net/java/language/inheritance.shtml Hope
how can i achieve multiple inheritance in java without using inheritance ?
how can i achieve multiple inheritance in java without using inheritance ?  how can i achieve multiple inheritance in java without using inheritance
Multiple Inheritance Problem - Java Beginners
Multiple Inheritance Problem  Hello Friend why Multiple Inheritance is not supported by java???? one of the answer i got that if there are three methods i. void show() in 3 super-classes named as A,B,C and if i extends A,B,C
Multiple inheritance using interface - Java Beginners
Multiple inheritance using interface  Hi, I understand.... But the use of the interface is when we use multiple inheritance with more than one... in multiple inheritance Thank you, Rajkanth  Hi Friend, Please
why java does not support multiple inheritance - Java Beginners
why java does not support multiple inheritance  hello friend, i knows that multiple inheritance is not supported in JAVA but this program looks ok... not support multiple inheritance directly but it supports multiple inheritance
inheritance
inheritance  how does one implement inheritance in java
Concept of Inheritance in Java
. Multilevel Inheritance In Multiple Inheritance, a parent class is extended... Multiple Inheritance however it can be achieved by using more than one interfaces...Concept of Inheritance in Java Concept of Inheritance in Java is considered
inheritance
inheritance  hi.. pleaseeeeee i need a quick help(answer) in creating aprogrm in java by using inheritance for car in such away that .... Car is parent class and both of Private and Public Car extends it then both of Bus
Exp.4 Write any C++ programs to demonstrate multiple inheritance concept of an object oriented programming.
Exp.4 Write any C++ programs to demonstrate multiple inheritance concept of an object oriented programming.  (Aim:- The main aim of this experiment...; Here is a code that demonstrates you the concept of multiple inheritance
Inheritance,Inheritance in Java,Java Inheritance
multiple Inheritance Multiple Inheritance The mechanism of inheriting the features of more than one base class into a single class is known as multiple inheritance. Java does not support multiple inheritance but the multiple inheritance can
Inheritance in java - Java Beginners
Inheritance in java  I want a example program using the concept of (simple and multiple) inheritance
Inheritance
Inheritance Multiple Inheritance The mechanism of inheriting the features of more than one base class into a single class is known as multiple inheritance. Java does not support multiple inheritance but the multiple inheritance can be achieved
Inheritance in java - Java Beginners
Inheritance in java  I want a example program using the concept of (single and multiple) inheritance.  Hi Friend, Please visit the following link: http://www.roseindia.net/java/language/inheritance.shtml Thanks
Inheritance
multiple Inheritance Multiple Inheritance The mechanism of inheriting the features of more than one base class into a single class is known as multiple inheritance. Java does not support multiple inheritance but the multiple inheritance can
Java inheritance
Java inheritance   can the child access protected content of the parent if the child is in a different project   If you have considered different project as different package then the child cannot access the content
javascript inheritance framework
javascript inheritance framework  javascript inheritance framework
Inheritance question?
Inheritance question?  Q3)Create a class hierarchy as Company extended by AccountsDepartment. AccountsDepartment extended by AccountsReceivable and AccountsPayables. The Company performs following operations. (1
Inheritance question?
Inheritance question?  Q3)Create a class hierarchy as Company extended by AccountsDepartment. AccountsDepartment extended by AccountsReceivable and AccountsPayables. The Company performs following operations. (1
Inheritance in Java
class. Multilevel Inheritance: Multiple Inheritance is when a subclass is derived... of level. * Though Java does not support Multiple Inheritance it can be achieved...Inheritance, one of the important concepts of Object Oriented Programming
Advertisements
 

 

 

DMCA.com