import java.io.*; import java.util.*; public class Greeter { /* We can initialize an instance variable when we declare it like this: */ //private String greeting="Go away"; private String greeting,happygreeting,sadgreeting; public Greeter() { happygreeting = "Nice to meet you"; sadgreeting = "Leave me alone"; } public Greeter (String happy, String sad) { setHappygreeting(happy); setSadgreeting(sad); } public Greeter(String g) { setGreeting(g); } /* This needs to be commented out because otherwise there will be two constructors with the same signature. I did not want to delete out any of the previous code already in here. public Greeter() { setGreeting("Hello"); } */ public void setHappygreeting(String smile) { happygreeting = smile; } public void setSadgreeting(String frown) { sadgreeting = frown; } public void setGreeting(String greet) { greeting = greet; } public String happyGreet(String name) { String message; message = happygreeting + " " + name; return message; } public String sadGreet(String name) { String message; message = sadgreeting + " " + name; return message; } public String greet(String name) { String message; message = greeting + " " + name; return message; } /* Examples of method overloading. Notice that each method has a unique signature, that is, the order and types of the parameters are unique. Java doesn't care about the parameter names */ public void f() { } public void f(String name1) { } public void f(String name1, String name2) { } public void f(String name1, int name2) { } public void f(int name1, String name) { } /* This one doesn't work because we already have a method f with a String, String signature public void f(String name2, String name1) { } */ }