I have to make only one show() method
public static void main(String[] args) {
show(new String("MATH"));
show(new StringBuilder("MINUS"));
show(new StringBuffer("%@&"));
}
String, StringBuilder, StringBuffer all implement CharSequence. They share some similarities they must get from that interface(read more about interfaces in Java, you can think about them as a kind of contract - classes that implement an interface must implement its methods), so you can write:
show(CharSequence someString){
//something to do
}
because:
CharSequence string1 = new String();
CharSequence string2 = new StringBuilder();
CharSequence string3 = new StringBuffer();
When in doubt about which classes implements which interfaces or extends which classes try searching in docs.
show(Charsequence stringToPrint)because all 3 String, StringBuilder, and StringBuffer implement Charsequence, so you can just pass that instead. That way, you can pass all of them to a single method.