| Author |
Inheritance in java
|
Subhendu Dash
Greenhorn
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
Bartender
Joined: Feb 26, 2001
Posts: 4115
|
|
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] [MiH]
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 5798
|
|
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: 30
|
|
|
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
Joined: Jan 03, 2004
Posts: 5798
|
|
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
Joined: Aug 20, 2001
Posts: 1815
|
|
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.
|
 |
 |
|
|
subject: Inheritance in java
|
|
|