wood burning stoves
The moose likes Java in General and the fly likes Inheritance in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Inheritance in java" Watch "Inheritance in java" New topic

Inheritance in java

Subhendu Dash

Joined: Mar 24, 2011
Posts: 18
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

Joined: Feb 26, 2001
Posts: 6529

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.

Junilu - [How to Ask Questions] [How to Answer Questions]
Jeff Verdegan

Joined: Jan 03, 2004
Posts: 6109

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

They're not.
egbai mmumene
Ranch Hand

Joined: Sep 18, 2012
Posts: 46
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

Joined: Jan 03, 2004
Posts: 6109

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

Joined: Aug 20, 2001
Posts: 1824

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.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
I agree. Here's the link: http://aspose.com/file-tools
subject: Inheritance in java
It's not a secret anymore!