Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why is implicit conversion allowed from superclass to subclass?

0
Posted

Why is implicit conversion allowed from superclass to subclass?

1

“. Actually, it’s the other way around. A subclass is an instance of the superclass, but not the other way around, so that’s why the types are not compatible. Imagine a very small superclass with just a single method or constant. Now imagine a subclass that defines everything including a kitchen sink. These are almost completely different types. However, the subclass is still an instance of the superclass; it does have that one method or constant. The superclass, on the other hand, has almost nothing that the inherited class implements., “Almost” is good enough for the parent to still be an instance of the child class, but passing the parent class to a method expecting the child would most likely not work, as hardly anything is available.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123