public class TEST {
String name1 = "Kelly";
String name2 = "Christy";
String name3 = "Johnson";
public static void main(String[] args) {
}
public void displaySalutation(String name1) {
displayLetter();
}
public void displaySalutation(String name2, String name3) {
displayLetter();
}
public void displayLetter() {
System.out.println("Thank you for your recent order.");
}
}
答案 0 :(得分:1)
主要方法需要调用包含打印行的方法。这可以通过创建包含要打印的方法的TEST实例来完成。然后调用实例变量中包含的方法 我已更新您的代码以显示如何创建实例并调用该方法。
public class TEST {
String name1 = "Kelly";
String name2 = "Christy";
String name3 = "Johnson";
// Define the entry point
public static void main(String[] args) {
// Create an instance of test
TEST test = new TEST();
/* Call the displayLetter method within TEST
Prints "Thank you for your recent order." */
test.displayLetter();
/* Call the printName method with the "Kelly" String as an argument.
Prints "Kelly" */
test.printName(name1);
}
// Prints a line
public void displayLetter(){
System.out.println("Thank you for your recent order.");
}
// Example print variable
public void printName(String name){
System.out.println(name);
}
}
我已经更正了你的代码,以便你可以调用displayLetter方法,但我不确定你想用其他两种方法做什么。