• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Inheritance in java

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 16669
278
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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

Junilu Lacar wrote:I'm not sure if interfaces are descendants of Object.



They're not.
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Bartender
Posts: 1843
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic