my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt on inheritance? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt on inheritance?" Watch "doubt on inheritance?" New topic
Author

doubt on inheritance?

Ashok Pradhan
Ranch Hand

Joined: Dec 17, 2007
Posts: 180

multiple inheritance is not possible in java,but when an class say that

class A extends B{}

then class A have two super classes one is class Object and other is class B.Is there any exception for class Object.
abhishek pendkay
Ranch Hand

Joined: Jan 01, 2007
Posts: 184
class A extends B{}

then class A have two super classes one is class Object and other is class B.Is there any exception for class Object.


class A has two sperclass but object is not a direct superclass of A. The above can be pictured as
class B extends Object{}
class A extends B{}
is this multiple inheritance...?? NO this is multi-level inheritance
multiple inheritance would be
class A extends B,Object{} and this is not allowed in Java
hope this clears your doubt


The significant problems we face cannot be solved by the same level of thinking which created them – Einstein
SCJP 1.5, SCWCD, SCBCD in the making
Ashok Pradhan
Ranch Hand

Joined: Dec 17, 2007
Posts: 180

Thanks Abhishek,

But is it true,when i declare a single class like :-

class A{} then class Object is the direct super class of A and when i declare class A extends B{} then it becomes class B is the direst super class of class A.

class A ---------Object

class A(---X---Object)-----B -----Object

where as
------- = extends
----X---- != extends[I know nothing for NOT EXTENDS only asume that it is]

please explain me wheather am I wrong.
Stevi Deter
Ranch Hand

Joined: Mar 22, 2008
Posts: 265

Ashok,

Perhaps it will help to realize it's hierarchical.

A is a B. B is an Object.

A is an Object, but only because it extends B which is an Object. This is an arbitrary example, of course, because ultimately all classes are Objects.

A can only be a type of object that is in its hierarchy of descent, and A can only have one parent class. Object is, in this example, A's grandparent class.

In Java, you can only extend from one class, and that's what's meant by only permitting single inheritance.


There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
abhishek pendkay
Ranch Hand

Joined: Jan 01, 2007
Posts: 184
Ashok
But is it true,when i declare a single class like :-

class A{} then class Object is the direct super class of A and when i declare class A extends B{} then it becomes class B is the direst super class of class A.


Yes you are right
 
 
subject: doubt on inheritance?
 
Similar Threads
Does Java Support Multiple Inheritance
Object class by default break to rule of multipul inheritance
multiple inheritance
Does JAVA support multiple inheritance or not
Someone explain me on inhertance.