Activity 5.11.1.
Write a method that overloads the talk method by taking in a name and printing
Hello
with that name.
Solution.
Overloading is when several methods have the same name but different parameter types, order, or number. In this case, the original method had no parameters and we overloaded it by creating a talk method with a String parameter.
public class Test1
{
public static void talk()
{
System.out.println("hello there!");
}
public static void talk(String name)
{
System.out.println("Hello " + name);
}
public static void main(String[] args)
{
talk("Matthew");
}
}