MHB Why Can Penguins Be Subtyped as Birds But Motorcycles Not as Cars in OOP?

  • Thread starter Thread starter tmt1
  • Start date Start date
  • Tags Tags
    Programming
AI Thread Summary
In object-oriented programming, the classification of a penguin as a subtype of bird is acceptable despite its differing attributes, such as the inability to fly, because it aligns with the concept of inheritance where a penguin is a specialized version of a bird. This reflects the principle of "is-a" relationships in which subtypes share a common base class. Conversely, a motorcycle cannot be classified as a subtype of a car because, despite both having similar behaviors like driving, a motorcycle does not fit the "is-a" relationship with cars. Instead, both motorcycles and cars are better categorized under a broader class, MotorizedVehicle, which accurately represents their shared characteristics without misrepresenting their distinct identities.
tmt1
Messages
230
Reaction score
0
For object oriented programming, why is is acceptable to have a
penguin be a subtype of bird even though a penguin has different
attributes than a bird(supposing we have a fly method) and yet it is
unacceptable for for Motorcycle to be a subtype of Car even though it
has the same behaviour (ie drive method)?
 
Technology news on Phys.org
tmt said:
For object oriented programming, why is is acceptable to have a
penguin be a subtype of bird even though a penguin has different
attributes than a bird(supposing we have a fly method) and yet it is
unacceptable for for Motorcycle to be a subtype of Car even though it
has the same behaviour (ie drive method)?

Hi tmt!

Both Car and Motorcycle are specializations of a MotorizedVehicle.
That's the one that has for instance a drive method.
Put otherwise, we can't say that a Motorcycle "is a" Car, since that is just not true.

On the other hand, we can treat a penguin as a more specialized version of a bird.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top