Basic abstract data type program

62 views Asked by At

This is homework but my teacher breezed through this part of the course during the lectures and I'm slightly lost.

We have to create a generic class Pair <A,B> like this:

public Pair(A itemA, B itemB)

public A first()

public B second()

The class will be used to stored and item and it's weight, like for example: Pencil,15

I just need a slight push to be able to do this

1

There are 1 answers

1
Epiglottal Axolotl On

All you really need to do is take the items in the constructor and store them in instance variables, which the first() and second() methods can return. When you declare the instance variables, you can declare their types as just A or B.