473,385 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Multiple inheritance

Dear Friends
I have a confution.....
In java all the class are extends java.lang.Object class.
Now suppose you write a class ----
public class B extends A
{
// Some code here
}

Logically, Here class B exteds class A and also extends class java.lang.Object. Now java does not support multiple inheritance. Then how does java handle this situation? Please explain it.

Thank you very much.

Debabrata
Aug 31 '07 #1
5 2636
r035198x
13,262 8TB
Dear Friends
I have a confution.....
In java all the class are extends java.lang.Object class.
Now suppose you write a class ----
public class B extends A
{
// Some code here
}

Logically, Here class B exteds class A and also extends class java.lang.Object. Now java does not support multiple inheritance. Then how does java handle this situation? Please explain it.

Thank you very much.

Debabrata
Yep, Java does not support multiple inheritance directly.

Multiple inheritance would be something like

Expand|Select|Wrap|Line Numbers
  1. class C extends B, A {
  2. }
  3.  
In your example, B extends class A only. Every class is a descendant of Object but that does not mean that every class extends Object.
Aug 31 '07 #2
dmjpro
2,476 2GB
Dear Friends
I have a confution.....
In java all the class are extends java.lang.Object class.
Now suppose you write a class ----
public class B extends A
{
// Some code here
}

Logically, Here class B exteds class A and also extends class java.lang.Object. Now java does not support multiple inheritance. Then how does java handle this situation? Please explain it.

Thank you very much.

Debabrata

A good Question you made.
I appreciate your thought.
Now look Inheritance,Data Encapsulation or may be Polymorphism all these things are Programming Paradigms.
Means decomposing a big problem.
And the syntax is for easy learning for programmers and for easy compilation.
But the ultimate native Code that is totally different from these things.
The compiler is much more intelligent to understand this situation.
Look, here B extends A and both of these classes extend Object.
Now if you are from C++ background then it will be easier to understand.
Actually to avoid this problem Java removes this Multiple inheritance.
Here, whatever it may be, you can access the method of java.lng.Object class.
Now have a look at another situation.
Like...!
Expand|Select|Wrap|Line Numbers
  1. Class A
  2. {
  3. void test(){}
  4. }
  5. interface B
  6. {
  7. void test();
  8. }
  9. class C extends A implements B
  10. {
  11. void test(){} 
  12. //Now here is a question method test is implementation of B or overriding of A.
  13. //Here the compiler would report, must be as public, because of implementing B
  14. //But whether you implement or override that does not a matter.
  15. }
  16.  
Java Compiler is much efficient to handle this situation very effectively.
Actually Java does not support Multiple Inheritance because of programmers have to take care of the Odd keyword Virtual as in C++.
I think now the picture is clear to you.

Kind regards,
Dmjpro.
Aug 31 '07 #3
kreagan
153 100+
Dear Friends
I have a confution.....
In java all the class are extends java.lang.Object class.
Now suppose you write a class ----
public class B extends A
{
// Some code here
}

Logically, Here class B exteds class A and also extends class java.lang.Object. Now java does not support multiple inheritance. Then how does java handle this situation? Please explain it.

Thank you very much.

Debabrata
I agree, this is an interesting question. My friend always told me, Java is ASEXUAL. This means that classes can have only 1 parent class (if it choose to).



In this LinkedList inherits functionality from its parent, grandparent (abstract list), and so forth. The grand daddy of them all is Object. Hopefully this linear representation will give you a clue. If you want your LinkList to have more properties, such as Queue properties, you must INTERFACE/IMPLEMENT Queue and fill in the Queues stub.

In C++ multiple inheritance means that a class can have more than 1 parent class.
Sep 2 '07 #4
JosAH
11,448 Expert 8TB
An interface is a pure type definition. A class is a type plus implementation
definition. Java does support multiple inheritance of types and it supports
single inheritance of implementation.

Java makes a distinction between types and implementations, C++ doesnt.
If C++ hadn't allowed for multiple inheritance it would've been a worthless little
language, OO-wise speaking, and just because it doesn't distinguish between
type and implementation it has to allow for multiple inheritance of implementation.

That's all there is to it.

Back to the OP's question: a class either explicitly extends from another class
or it implicitly extends from the Object class; so all classes form a tree in which
every node (indirectly) extends from the Object class.

kind regards,

Jos
Sep 2 '07 #5
praveen2gupta
201 100+
Dear Friends
I have a confution.....
In java all the class are extends java.lang.Object class.
Now suppose you write a class ----
public class B extends A
{
// Some code here
}

Logically, Here class B exteds class A and also extends class java.lang.Object. Now java does not support multiple inheritance. Then how does java handle this situation? Please explain it.

Thank you very much.

Debabrata
Hi
Object is the super class of all classes in java.
Case1.
public class B extends A
{
// Some code here
}

class B is inherting only class A It is not inheriting class Object, and class A is inheriting class Object Class B is inheriting only one class at a time that is class A
so it is not multiple inheritance.

Case 2
public class B
{
// Some code here
}
In this case class B is inheriting class Object by default.
Sep 3 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
5
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
20
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
15
by: iKiLL | last post by:
hi all, I would like to be able to create an umbrella class for all my main global sections but I would still like to keep them all in separate file something like the below but I keep getting...
7
by: Adam Nielsen | last post by:
Hi everyone, I'm having some trouble getting the correct chain of constructors to be called when creating an object at the bottom of a hierarchy. Have a look at the code below - the inheritance...
47
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
2
by: Paul McGuire | last post by:
On May 25, 8:37 am, Michael Hines <michael.hi...@yale.eduwrote: Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). --...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.