File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes doubt about extend keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "doubt about extend keyword" Watch "doubt about extend keyword" New topic
Author

doubt about extend keyword

Manish Jaju
Greenhorn

Joined: Jul 21, 2004
Posts: 24
Why doesn't Java allow multiple inheritance using extend keyword, i mean, why java allow only one class to extend.. Please clarify.
sarada konda
Greenhorn

Joined: Dec 10, 2004
Posts: 7
Explaning ur doubt with an example
suppose that a class can extends more than one class

class A
{
public void method1()
{
System.out.println("class A method");
}
}

class B
{
public void method1()
{
System.out.println("class B method");
}
}

class C extends A, B
{
public static void main(String s[])
{
C c = new C();
c.method1(); //here is the ambiguity
}
}

the ambiguity raises because it doesn't know which method to be called either of ClassA or of ClassB
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Although such ambiguity is one argument against multiple inheritance, it does not make it impossible. Other languages have multiple inheritance, and get around the ambiguity issue by various means.

I believe that the true reason Java does not have multiple inheritance is that it makes things simpler. JVMs and compilers are simpler to write, may be smaller and may run faster. Single inheritance source code is also usually easier to understand and to maintain, though that may not always be the case: if a problem lends itself to an obvious solution by multiple inheritance, which has to be "kludged" in a single-inheritance language, for example.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Java doesn't support multiple inheritance because the language designers don't think multiple inheritance is a good idea (and many people agree with them).

As a result multiple inheritance is not in the language specification which means it's not part of the language.

No other reason is needed.


42
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
To understand why Java doesn't support multiple inheritance, you should look at how Java got its start.

James Gosling was leading a programming project at Sun Microsystems using C++ and found that his team was spending as much time dealing with the complexities of the language as they were writing programs.

He decided to design a new C family language that, among other things, eliminated the language features that were difficult to understand and apply to real programs. Selecting the correct C++ function to dispatch with multiple inheritance has rules bordering on the metaphysical. Since we can't all be as smart as C++ inventor Bjarne Stroustrup, Gosling substituted multiple implemented interfaces, where the issue of choosing between method implementations never arises.

It's important to remember that programming languages were designed by real people with specific goals. No one language is right for every purpose. By understanding the design objectives of different languages, you are better equipped to choose the best one for your project.


Mike Gershman
SCJP 1.4, SCWCD in process
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt about extend keyword
 
Similar Threads
interface
Question on Interfaces
multiple inheritance
Interface Extend vs Implement Another Interface
Question on Interfaces