5
votes

From the pdf of a java course: http://www.ccs.neu.edu/home/riccardo/courses/csu370-fa07/lect4.pdf

It says:

For those of you that follow at home, let me emphasize that subclassing is not inheritance. We will see inheritance later in the course.

Of course, subclassing and inheritance are related. As we will see inheritance is a code reuse mechanism that lets you reuse code easily when defining subclasses. But subclassing makes sense even when you do not have inheritance.

(Indeed, some languages have subclassing but no inheritance, at least, not inheritance like Java implements.)

Subclassing is a property of classes, and is properly part of the type system of Java. Subclassing is used by Java to determine what methods can possibly be invoked on an object, and to return an error at compile-time when an object does not supply a given method.

I want to know which languages have subclassing but no inheritance, at least, not inheritance like Java implements? (Since I'm not quite understand the concepts, so if I can see it in some actual languages, that would make it clearer)

1
I don't see the point for such a language, but theoretically it may be possible. I can only imagine that some lower-level (and barely known) language has this behavior. - gaborsch
The author of the course should have cited at least one example. Not doing so makes the parenthetical fail the weasel-words test. I've never seen a language with subclassing but not inheritance. Type systems, but not languages. COM, for instance, has a concept of subclassing but is language-neutral and doesn't within COM itself directly support inheritance (I don't think). - T.J. Crowder
I guess it also depends on your definition of "language." In the above, I'm thinking "language" = "programming language," but the word is more general than that. "Interface Definition Languages" for instance frequently call themselves "languages" but are concerned solely with specifying interfaces; they do no implementation at all (and therefore no inheritance, just subclassing). But HTML calls itself a "language" as well, while clearly not being a programming language. - T.J. Crowder
"I want to know which languages have subclassing but no inheritance, at least, not inheritance like Java implements?" I can't give you an example of that, so this isn't an answer, but I can give you an example going the other way: JavaScript has inheritance but doesn't have subclassing. I think this is true of many of the languages based on prototypical inheritance (but I really only know the one). - T.J. Crowder

1 Answers

3
votes

This is a distinction without a difference. Clearly he is talking about inheritance of methods only when he uses the word "inheritance". He isn't using the term in the canonical way introduced by Wegner87, which is inextricably entwined with subclassing:

Inheritance: A class may inherit operations from “superclasses” and may have its operations inherited by “subclasses”. An object of the class C created by the operation “C new” has C as its “base class” and may use operations defined in its base class as well as operations defined in superclasses.

CS teachers often have strange notions. This has been one of them.