• 2021-04-14
    分析下面的程序,输出的结果是?
    public class Test {
    public static void main(String[] args) {
    final Person p = new Person("张三", 23);
    p.setName("李四");
    p.setAge(24);
    System.out.println(p);
    }
    }
    class Person {
    private String name;
    private int age;
    public Person() {
    super();
    }
    public Person(String name, int age) {
    super();
    this.name = name;
    this.age = age;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public int getAge() {
    return age;
    }
    public void setAge(int age) {
    this.age = age;
    }
    @Override
    public String toString() {
    return "我的姓名是:" + name + ",我的年龄是:" + age ;
    }
    }
  • 举一反三