Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt on inheritance?

 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
abhishek pendkay
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic