aspose file tools*
The moose likes Beginning Java and the fly likes Why one can't extend more than one class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why one can Watch "Why one can New topic
Author

Why one can't extend more than one class

Rajesh Thorat
Greenhorn

Joined: Jun 29, 2010
Posts: 3
Let's say we have a scenario like, a class 'A' is extended by two classes 'B' and 'C'.
Now, class 'D' extends class 'B' and want's to access class 'C'.
Here, we'll get an error here or we'll not allowed to do so.
Now, my query is, whenever 'D' wants to extend 'C', it must check whether 'B' and 'C' are having same base class or not.
If 'B' and 'C' are not derived from same base class, then 'D' must allowed to extend two classes at a time.


@
Rajesh Thorat
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19060
    
  40


Just do a search for multiple inheritance. This question has been asked many times.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Rajesh Thorat
Greenhorn

Joined: Jun 29, 2010
Posts: 3
Henry Wong wrote:
Just do a search for multiple inheritance. This question has been asked many times.

Henry


I know why we can't extend. But the thing is can Developers who developed java design it in such a way, that ,
Class 'D' can allowed to extend more than one classes, provided the classes which it going to extend should not share a same
Base class.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

A Java class can extend a single class, period.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
Rajesh Thorat wrote: . . . provided the classes which it going to extend should not share a same Base class.
Apart from "base class" being a C# term, rather than a Java term (we say superclass), all Java classes share the same superclass, viz java.lang.Object.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why one can't extend more than one class