日期:2014-05-20 浏览次数:20600 次
public class TestOverLoad { public static void main(String[] args) { Person p = new Person(); Person p1 = new Person(400); Person p2 = new Person(2, 500); p.info(); p.info("ok"); } } class Person { Person() { id = 0; age = 20; } Person(int _id) { id = _id; age = 23; } Person(int _id, int _age) { id = _id; age = _age; } //成员变量定义 private int id; private int age = 20; [color=#FF0000]//方法定义 public int getAge() {return age;} public void setAge(int i) {age = i;} public int getId() {return id;} 这三句话是不是没有用处啊 ? 写不写 结果都是一样的。。具体有有什么用呢》?上面不是已经定义过方法了么?? [/color] void info() { System.out.println("my id is : " + id); } void info(String t) { System.out.println(t + " id " + id); } }