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...!
-
Class A
-
{
-
void test(){}
-
}
-
interface B
-
{
-
void test();
-
}
-
class C extends A implements B
-
{
-
void test(){}
-
//Now here is a question method test is implementation of B or overriding of A.
-
//Here the compiler would report, must be as public, because of implementing B
-
//But whether you implement or override that does not a matter.
-
}
-
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.