0

This is for a homework assignment. Basically, the idea is to create a subclass of ArrayList in the Inventory class, meaning the Inventory class will inhert from ArrayList and be able to store instances of the Item class.

So my understanding is that I would create a Inventory class and with ArrayList to connect to the Inventory?

1 Answer 1

1

ArrayList is just a class and, as with any other (non-final) Java class, you can extend from it by using extends:

public class Inventory extends ArrayList<Item> {
    //override necessary methods here
}
Sign up to request clarification or add additional context in comments.

7 Comments

So from what I am reading from your answer is that i would have to create the arraylist seperate from the inventory class or inside the class you just wrote?
@user4146749 your question states: the Inventory class will inhert from ArrayList and be able to store instances of the Item class since you have to inherit then you will use extends. If you have a field List<Item> itemList = new ArrayList<Item>(); then you're not extending but using composition.
sorry if I am asking too much but I am just having a hard time understanding it due to the fast pace of the topic. So like this? public class Inventory extends ArrayList<Item> List<Item> itemList = new ArrayList<Item>();
@user4146749 I guess you first define what you really have to do, review the concepts and apply the proper solution. I cannot read your mind, sorry.
@user4146749 you should not do the both, it doesn't make any sense.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.