File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes same method inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "same method inheritance" Watch "same method inheritance" New topic
Author

same method inheritance

karimkhan pathan
Ranch Hand

Joined: Jul 14, 2008
Posts: 86



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.


karim
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Aug 16, 2005
Posts: 14266
    
  21

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 13, 2005
Posts: 39386
    
  28
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

Joined: Feb 10, 2009
Posts: 710
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.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39386
    
  28
Yes, I think you are right. It was daRn, so the spelling was correct. Sorry
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I could have been talking about beavers. Or just really industrious children that enjoy civil engineering.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39386
    
  28
But baby beavers aren't called kids. Maybe you meant the sort of goat which drops trees in rivers?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: same method inheritance