ArrayList must contain unique objects (Inheritance)
I am new to Java, I am woring on learning inheritance.
I am creating an abstract class called Thing.
I have to put this requirement in, Please could somebody help me with Syntax
Thing will have the following private class field:
• Things, an ArrayList defined with a Thing generic. This ArrayList must be maintained as Thing objects are constructed. This ArrayList must contain all unique objects for which (object instanceof Thing) is true. Each time an object for which (object instanceof Thing) is true is constructed, a reference to that object must be put in the ArrayList, if that object does not already exist in the ArrayList. The Thing equals method will be used to test if the object is not unique, i.e., already exists in the ArrayList. Your code must not useany object casts and must not use any instance of operator.
public abstract class Thing
public String iName = new String();
private ArrayList<Thing> iThings = new ArrayList<Thing>();
public static void main(String args)
Thing vehicle1 = new Vehicle();
public Thing(String name)
iName = name;
public String getName()
public abstract void show();
public abstract boolean equals(Thing b);
public void showThings()
Re: ArrayList must contain unique objects (Inheritance)
Moved from 'Java Applets'. In future, please post in an appropriate forum -- the question has nothing at all to do with Applets.
Also, please use code tags for posting code. I've added them for you this time.