So there is a class called Product. Which has products like ComputerParts and Fruit. I have made a container called genericOrder which accepts type product. I'v added an object of ComputerPart to it. Now i need to Have a subclass of genericOrder called computerOrder which takes the subclasses of ComputerParts which are Ram, CPU etc.
How do i link the container to genericOrder ? i have attached the code below . Forgive me i am very new to programming
import java.util.*;
public abstract class GenericOrder {
public static void main(String[] args) {
List < Product > genericOrder = Arrays.asList(new ComputerPart(12), new ComputerPart(76f),
new Service(26f), new Cheese(26f), new Fruit(26f), new Peripheral(26f));
}
}
Use generics. Something on these lines...
Then: