This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

same method inheritance

 
karimkhan pathan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



output :
Parent class
Parent class
Parent class

I want to know when there no compile time error when we are not implementing method() in the Child class.

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
karimkhan pathan wrote:
I want to know when there no compile time error when we are not implementing method() in the Child class.


Because Child has method() implicitly from Parent right?

also interface doent have the method implementation. so there is no Deadly Diamond of Death problem in java unlike C++
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
karimkhan pathan wrote:there is no Deadly Diamond of Death problem in java unlike C++

Yes, fortunately, we're forced to re-implement behavior over and over in Java.

While I'd prefer something like traits or mixins, at least multiple inheritance allowed me to remove a ton of duplication.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A note about the names of your classes:

Note that "inheritance" in terms of object oriented software has a different meaning than inheritance in the biological sense. Calling classes "Parent" and "Child" confuses the object oriented programming meaning of the word with the biological meaning.

It's very important to understand that subclassing in object oriented programming means that you create a specialized version of the superclass. There is an "is a" relationship between the superclass and the subclass: an instance of the subclass is an instance of the superclass (with things added to it).

If you call your superclass "Parent" and your subclass "Child", then what you're saying is: A Child is a Parent, which is obviously false if you think about the meaning of the words "Parent" and "Child".

It's better to use for example the words "Animal" and "Dog" instead of "Parent" and "Child" - a Dog is an Animal.

There's no such thing as a "parent class" and a "child class" - we call those superclasses and subclasses.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper Young wrote:It's better to use for example the words "Animal" and "Dog" instead of "Parent" and "Child" - a Dog is an Animal.

So are children, so this works all around. Darn kids.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote: . . . So are children, so this works all around. Darn kids.
Mine aren't (at least if they are they haven't told me yet )

And it's spelt damn.
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
David Newton wrote: . . . So are children, so this works all around. Darn kids.
Mine aren't (at least if they are they haven't told me yet )

And it's spelt damn.


I believe he put daRn, not dam, although on my screen that did look like dam.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I think you are right. It was daRn, so the spelling was correct. Sorry
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could have been talking about beavers. Or just really industrious children that enjoy civil engineering.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But baby beavers aren't called kids. Maybe you meant the sort of goat which drops trees in rivers?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic