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

Inheritance in java

 
Subhendu Dash
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Was going through inheritance chapter in Kathy's java6 book..And came across a line that states that :"Its almost impossible to do anything in java without using inheritance "..And when i read "almost".i wonder is it even possible in java to do anything that doesn't uses the concept of inheritance?..since whatever we create in java extends from java.lang.Object
 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if interfaces are descendants of Object. You can define an interface that specifies a contract for behavior and until there's an implementation of that interface, inheritance mechanisms don't really come into play yet.

It's not a bad thing to want to thoroughly understand what the author is saying but frankly, things like this are not really a practical concern and it kind of makes me wonder whether this is somehow going to end up in a future list of "interview questions" along with a bunch of other annoying and practically irrelevant "trivia" questions about Java. Understand but don't over-analyze.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:I'm not sure if interfaces are descendants of Object.


They're not.
 
egbai mmumene
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
don't really disturb yourself with that at the moment. although if you want to inherit from another class you have to use the extends keyword
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
egbai mmumene wrote:if you want to inherit from another class you have to use the extends keyword


Not true.


My Foo class inherits from Object.


 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on what you mean by "Using," and who is doing this using.

You can write procedual programs in Java -- Hello World is a procedual program. Even though the class is an object and there are object-oriented implementation details (and the call to System.out.println may make use of an inheritance hierarchy), the logic shows none of the hallmarks of object-oriented design; you are not even creating an instance of the class executing the code. You can pick that code up and move it to C with minimal effort and no change to the design. Therefore, I cannot say that you are using inheritance in HelloWorld.

More to the point of the book, however, is that when designing programs using Object-oriented principles, inheritance is one of the more important design concepts. Any non-trivial program should make use of inheritance in its design; not doing so results in code that is nearly impossible to maintain as the project grows and matures.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic