Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why one can't extend more than one class

 
Rajesh Thorat
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 21117
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Henry
 
Rajesh Thorat
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Java class can extend a single class, period.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48957
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic