asked in Inheritance by (58.6k points)

1 Answer

Yes, you can pass that because subclass and superclass are related to each other by Inheritance which provides IS-A property.  I mean Banana is a Fruit so you can pass banana if somebody expect fruit. Now there are scenario, where you can't do e.g. when subclass violates the Liskov Substitution principle i.e. you cannot pass a plastic banana to someone expecting fruit :-), The eat() function will throw exception.
 

Liskov Substitution Principle in Java


 

answered by (58.6k points)

Java Interview Questions and Answers 2018

...