Skip to main content
13 events
when toggle format what by license comment
Oct 6, 2017 at 20:13 comment added Doc Brown @wolfrevo_kcats: ... sure, and my answer is: all derived Java classes are examples of polymorphism since inheritance / subtyping always implies polymorphism (except for some edge cases like the ones mention by FrankHileman). That is what that article says, to my understanding.
Oct 6, 2017 at 17:04 comment added wolfrevo_kcats @DocBrown I was asking about how polymorphism and inheritance are related, but not "in general." I think the article talks about subtype polymorphism the entire time and doesn't talk about any other type of polymorphism that isn't achieved through inheritance. So my question was why the article is saying that all derived Java classes are examples of subtype polymorphism.
Oct 5, 2017 at 18:59 comment added Doc Brown @FrankHileman: it seems you are missing my point. The whole question is about how the concept of polymorphism and the concept of inheritance are related in general. It does not matter that one can artificially construct some edge-case examples where inheritance does not lead to real polymorphism, still in general inheritance - as a concept - is one way, but not the only way, to implement polymorphism.
Oct 5, 2017 at 18:48 comment added Frank Hileman Well, that is not the only case. Suppose the base class A has no virtual members. A call on a derived instance, when cast as A, cannot be polymorphic. For me, the definition has to do with whether a call site can be resolved at compile time or run-time, specifically with instance calls.
Oct 5, 2017 at 11:39 comment added Doc Brown @FrankHileman: nitty, nitty ;-) My answer tries to explain what the original article meant, and where the OPs confusion comes from, no less, no more. What you mention is IMHO a debatable edge case.
Oct 4, 2017 at 23:09 comment added Frank Hileman "as soon as a class inherits...." Suppose internal abstract class A has only one derived class, B. Is an instance of A polymorphic (ignoring the mandatory Object root)? I would say not, as we can tell from static analysis that an instance of A must be an instance of B. If A was public, anyone could extend it, and the argument breaks down.
Oct 4, 2017 at 21:14 comment added Doc Brown @wolfrevo_kcats: sure it is. That's exactly the point of my answer. The article starts with polymorphism in its general meaning, and then explains how it is achieved in Java using inheritance. It seems you believe my answer does not apply to your question. It does, if you have problems understand why, let me know exactly what's not understandable.
Oct 4, 2017 at 21:06 comment added wolfrevo_kcats Thanks for your reply. The article I linked was referring to subtype polymorphism, which by definition is achieved only through inheritance. I should have been more specific with the scope of my question, namely subtype polymorphism in C# (or Java).
Oct 3, 2017 at 21:04 history edited Doc Brown CC BY-SA 3.0
deleted 7 characters in body
Oct 2, 2017 at 21:24 history edited Doc Brown CC BY-SA 3.0
added 152 characters in body
Oct 2, 2017 at 20:22 history edited Doc Brown CC BY-SA 3.0
added 223 characters in body
Oct 2, 2017 at 20:15 history edited Doc Brown CC BY-SA 3.0
added 223 characters in body
Oct 2, 2017 at 20:08 history answered Doc Brown CC BY-SA 3.0