创建对象赋值的顺序

public class Student6 {
    private String name = "魏一民";
    private int age = 18;

    public Student6() {
    }

    public Student6(String name, int age) {
        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;
    }

    public void show() {
        System.out.println("姓名: " + this.name + "年龄:" + this.age);
    }
}

class Student6Demo{
    public static void main(String[] args) {
        Student6 s1 = new Student6("李四",22);
        s1.setName("张三");
        s1.setAge(20);
        s1.show();
    }
}
posted @ 2024-08-01 21:12  ていせい  阅读(2)  评论(0编辑  收藏  举报