• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Object Class Method Access Problem

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 172
Python MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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. :-)
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a interface we can also use equals and other methods?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic