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
Click For 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.
 
Anthropic announced that an inflection point has been reached where the LLM tools are good enough to help or hinder cybersecurity folks. In the most recent case in September 2025, state hackers used Claude in Agentic mode to break into 30+ high-profile companies, of which 17 or so were actually breached before Anthropic shut it down. They mentioned that Clause hallucinated and told the hackers it was more successful than it was...

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 8 ·
Replies
8
Views
7K
Replies
3
Views
12K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K