Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which languages "have subclassing but no inheritance"?

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)

like image 655
Freewind Avatar asked Oct 21 '22 06:10

Freewind


1 Answers

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.

like image 88
user207421 Avatar answered Oct 24 '22 12:10

user207421