• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

same method inheritance

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

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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++
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I think you are right. It was daRn, so the spelling was correct. Sorry
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I could have been talking about beavers. Or just really industrious children that enjoy civil engineering.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But baby beavers aren't called kids. Maybe you meant the sort of goat which drops trees in rivers?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic