JAVA-JavaBean类

image
image

package com.itheima03;

public class Student {
    private String name;
    private int age;

    public Student(){};

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

    public String getName() {
        return name;

    }
    public void setAge(int age){
        this.age=age;

    }
    public int getAge(){
        return age;
    }

}

代码2

package com.itheima03;

public class StudentDemo {
    public static void main(String[] args) {
        Student s1=new Student();

        s1.setName("林青霞");
        s1.setAge(30);
        System.out.println(s1.getName()+","+s1.getAge());

    }
}

执行结果

林青霞,30

Process finished with exit code 0

posted @ 2022-11-13 16:38  NiceTwocu  阅读(20)  评论(0编辑  收藏  举报