Discuss / Java / 练习:给Person增加重载方法

练习:给Person增加重载方法

Topic source

YANGZY1202

#1 Created at ... [Delete] [Delete and Lock User]
//Main.java
public class Main {

	public static void main(String[] args) {
		Person ming = new Person();
		ming.setName("Xiao Ming");
		System.out.println(ming.getName());
		Person hong = new Person();
		// FIXME: 给Person增加重载方法setName(String, String):
		hong.setName("Xiao", "Hong");
		System.out.println(hong.getName());
	}

}
//Person.java

public class Person {

	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setName(String preName, String postName) {
		this.name = preName + " " + postName;
	}
}

傅小司06

#2 Created at ... [Delete] [Delete and Lock User]

上面的说明我完全看不懂,都看完了都不知道在讲什么?

honnnnnnnnnng

#3 Created at ... [Delete] [Delete and Lock User]

形参也可以是字符串数组吗?


  • 1

Reply