If ‘apple’ is a subclass of ‘fruit’ , then List<apple> is a subclass of List<fruit> is this correct ?
If ‘apple’ is a subclass of ‘fruit’ , then List<apple> is a subclass of
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No.
List<apple>andList<fruit>are not related. These both classes could have totally different implementations and there is no way to convert one into the other. For example theList<>template could be specialized in some way forapples that has a totally different structure than the generalList<T>template.And even if the implementations were compatible, it would still be a bad idea to treat a
List<apple>as aList<fruit>since then people would start to put all kinds of fruits into that list that was just supposed to contain apples. See also this entry in the C++ FAQ Lite, that talks about apples and bananas…