Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java inheritance  RSS feed

 
subhakar edeti
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
every body aware object class is super class of every class in java.
means every class extends the Object class.
class A extends B{} already extends Object class in this a can have
properties of both object and b class how this is posible even though java
doesn't supprot multiple inheritance.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by subhakar edeti:
every body aware object class is super class of every class in java.
means every class extends the Object class.
class A extends B{} already extends Object class in this a can have
properties of both object and b class how this is posible even though java
doesn't supprot multiple inheritance.


Class A inherits from the Object class as a result of extending class B because class B is an Object. A does not extend both ClassB and Object. So you have a linear hierarchy like so

Object-> Class B --> Class A.
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Speaking of multiple inheritance, if you ever feel that you need it, you can declare your class to imiplement interfaces in addition to inheriting from a single parent class.

-- Kaydell
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not inheritance, it's implementation...

btw, Java does support multiple inheritance but only of interfaces.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!