I have two Java classes that both have the same method (the foo method in the example), like:
public class Class1 {
    private String var = "HELLO";
    public String getString() {
        return foo(var);
    }   
    private int foo(String s) {
        return s.hashCode();
    }
}
public class Class2 {
    private String var = "WORLD";
    public String getString() {
        return foo(var);
    }   
    private int foo(String s) {
        return s.hashCode();
    }
}
The method foo is the same, it change only the parameter I use with it. 
So is it better create a superclass with the foo method and two subclass or create an interface? I am not so sure about the interface, because I will write again the code in the two classes.
Some advice?