Replacement in Java

As with many things, replacement in Java uses a similar syntax, but slightly different semantics. There is no virtual keyword. All objects are potentially polymorphic, and replacmenet occurs whenever a child class redefines a method using the same name as a method in the parent class.

You can even replace data fields, although these are statically bound based on the declared type, not the dynamic value.

An interesting feature in Java is the final keyword. This can be used to prohibit replacmenet. Declaring a class as final prohibits subclassing altogether. This is an interesting idea, and may permit a Java system to do optimizations that might not otherwise be possible. There is no similar facility in C++.

[audio] [real] Text to accompany slide10, in Chapter 11 of An Introduction to Object-Oriented Programming