I have created two classes, class A that uses a Linked List and class B that uses an ArrayList. Both classes have a method add(), which adds an elements to the LinkedList or ArrayList reciprocally.
My question is: Is it possible to create another class, say C, such that C has its own method add() to add elements to a LIST, and class C is the parent of A and B and also that A and B inherit the add() method of class C without overriding it???
P.S: I tried to do this myself but I get an error because I cannot initialize a list in class C. I am using Java
Thank you in advance
It is possible. Below is the example. I haven’t compiled it as I just wanted to give you the idea.