First of all, you can not create objects from an abstract class so you need to change that or just forget about that constructor because you won't be able to use it.
To compare two objects you need to create a comparator class so you would be able to compare objects according to the attributte you want to.
So in this case you need to create two comparators, one to compare them by unit of measure and another to compare it by quantity.
So it would be something like this:
Comparator by unit of measure:
public class UnitOfMeasureProdusComparator implements Comparator<Produs> {
@Override
public int compare(Produs p1, Produs p2) {
return p1.getUnitateMasura().compareTo(p2.getUnitateMasura());
}
Comparator by quantity:
public class QuantityProdusComparator implements Comparator<Produs> {
@Override
public int compare(Produs p1, Produs p2) {
return p1.getCantitate().compareTo(p2.getCantitate());
}
So now for example if you have an arraylist of Produs objects you can compare them like this:
ArrayList<Produs> products = new ArrayList<>();
Produs p1 = new Produs("x", "centimeters", 5);
Produs p2 = new Produs("y", "meters", 4);
products.add(p1,p2);
//now you have two objects created so if you want to sort them by there quantity u can do it like this:
Collections.sort(productos, new QuantityProdusComparator());
It will sort the list according to the comparator you use.
Internally the comparator class will send a 0 if the objects are equal, a -1 if the object is smaller than or a 1 if the object is bigger than.
If you comparing string attributes it will do it in alphabetical order.