In: Computer Science
Pick a pair of concrete classes in the JDK in a parent-child relationship and discuss a few polymorphic and/or overloaded methods. Do not use Object as the parent class - it is too trivial to address the issues to be addressed here, and in any case, Object is the final parent of all classes in Java.
Parent Class - Array List
Child class - Attribute List
Concrete class :
public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, Serializable
public class AttributeList extends ArrayList<Object>
Overloaded method :
In Parent Class -
boolean add(E e)
Appends the specified element to the end of this list.
void add(int index, E
element)
Inserts the specified element at the specified position in this
list.
In Child class -
void add(Attribute object)
Adds the Attribute specified as the last element of the list.
void add(int index, Attribute object)
Inserts the attribute specified as an element at the position
specified.
Overriding a method :
public boolean add(Object element)
Appends the specified element to the end of this list.
Overrides: add in class ArrayList<Object>