January 2020
Intermediate to advanced
532 pages
13h 31m
English
Implementation inheritance allows a subclass to inherit both fields and methods from its superclass. As Julia does not support implementation inheritance, we will switch language for a moment and present the following example in Java. Here is a class that provides a container for holding any number of objects:
import java.util.ArrayList;public class Bag{ ArrayList<Object> items = new ArrayList<Object>(); public void add(final Object object) { this.items.add(object); } public void addMany(final Object[] objects) { for (Object obj : objects) { this.add(obj); } }}
The Bag class basically maintains a list of objects in the items field and provides two convenient functions, add and addMany, for adding a ...
Read now
Unlock full access