posts - 137,comments - 0,views - 40595

创建Student类的对象,并为相应属性赋值,并打印输出各属性值。

复制代码
class Student{
        private long studentId;
        private int classId;
        private int age;
        private String studentName;

        public long getStudentId(){
            return studentId;
        }
        public void setStudentId(long studentId){
            this.studentId=studentId;
        }

        public int getClassId(){
            return classId;
        }
        public void setClassId(int classId){
            this.classId=classId;
        }

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

        public String getStudentName(){
            return studentName;
        }
        public void setStudentName(String studentName){
            this.studentName=studentName;
        }
        public void read(){
            System.out.println("大家好,我是"+studentName+",学号是"+studentId+",来自软工"+classId+"班,今年"+age+"岁,很高兴认识大家!");
        }
}
public class Student_Example1 {
    public static void main(String[] args){
        Student stu=new Student();
        stu.setStudentId(2088999977771L);
        stu.setClassId(02);
        stu.setAge(22);
        stu.setStudentName("张小明");
        stu.read();
    }
}
复制代码

posted on   wshidaboss  阅读(2468)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示