New course! Every coder should learn Generative AI!
Try a free lesson+ 1
methods...
how does the second method know that david or amy = name??
4 Answers
+ 2
the method static void sayHello(String name) is a method with an argument, String name. What this means, is that when the method is called in the main method, sayHello("David"); the David string is being put into the argument name. So essentially, name becomes "David". The method is called again with sayHello("Amy"); This time, name becomes the string "Amy". Method sayHello just prints out hello with the value of String name at the time it is called.
If you were to try to call the sayHello(); with no name, you'd get an error because you're not passing a value for the argument.
+ 1
class MyClass {
static void sayHello(String name) {
System.out.println("Hello " + name);
}
public static void main(String[ ] args) {
sayHello("David");
sayHello("Amy");
}
}
0
my bad i thought the questions were divided for each "page"
0
"bavid"