• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object Class Method Access Problem  RSS feed

 
Chirag Sharma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every Java Class Extends Object class.

Lets discuss with an example:
1)
class A {//default extends Object
}

2)
class B extends A {//default extends Object
}

why we are not getting problem (ambiguity problem named in C) here?
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chirag Sharma wrote:Every Java Class Extends Object class.

Lets discuss with an example:
1)
class A {//default extends Object
}

2)
class B extends A {//default extends Object
}

why we are not getting problem (ambiguity problem named in C) here?


Can you be more clear with your question?

With what I have understood from your question, my response is:

Its not Multiple Inheritance as you think.

Can you try this:


Its a multilevel inheritance and not multiple inheritance as you think.
 
Chirag Sharma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sanaulla,

Thanks for reply.
I want to ask that .. according to my example...
... class A extends Object class
... class B extends Object class
... and B also extends A

So its looks like a multiple inheritence...
....i think its clear now.
 
Ashish Dutt
Ranch Hand
Posts: 172
Java MySQL Database Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Chirag,

To quote what you quoted earlier, "Every Java Class extends Object" True
Lets take an example, In the very beginning when there was nothing it was just Adam and Eve ...after that you know rest all is history because from these two (read Objects) were derived numerous ethnic origins (read classes, methods, variables etc)
So, the above crude example filters down to the following gospel truth;
1) Java does not support multiple inheritance (i.e.The human race has its roots with Class Eve implementing Adam interface or Class Adam implementing Eve interface )
2) Its the Class that gives birth to an object (the birth process is invoked by using the new keyword and not the opposite.

Hope this helps in clearing the mist. :-)
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chirag Sharma wrote:So its looks like a multiple inheritence...

No it doesn't. Where does it say
class B extends Object
?

The fact is that class B extends class A, which in turn extends Object - which means that class B is-a A, and since class A is-a Object, it follows that class B is-also-a Object, but that's not the same thing as multiple inheritance.

Don't you think it would be kind of silly if inheritance only allowed you to create hierarchies that were two-deep? Since, as you've already worked out, everything basically extends from Object, that would rule out hierarchies altogether, wouldn't it?

Winston
 
Chirag Sharma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a interface we can also use equals and other methods?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chirag Sharma wrote:In a interface we can also use equals and other methods?


What do you mean?

In an interface we don't have any executable code, just declarations. (Okay, there can be a class nested in an interface, but that's an oddball case, and probably not what you're talking about).

However, if you mean something like this:


then yes, we can do that (and you could have found that out for yourself just by writing some code to test it). Section 9.2 of the JLS says that if an interface does not extend another interface, then it implicitly declares equals() and all the other public methods that are declared on Object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!