当前位置:首页 > Java > 正文内容

10. 编写一个学生类Student 要求: (1) 学生类Student属性有: id :long型代表学号 name :St

2023-12-01Java

10. 编写一个学生类Student 要求: (1) 学生类Student属性有: id :long型代表学号 name :String类对象,代表姓名 age :int型,代表年龄 (2) 学生类Student方法有: Student(long l ,String a, int b)有参构造函数,形参表中的参数分别初始化学号、姓名、年龄。 intgetAge() :获取年龄作为方法的返回值。 public String toString() :以姓名、学号的形式作为方法的返回值 代码如下; public class Student { private long id; private String name; private int age; public long getId() { return id; } public void setId(long id) { this.id = id; } 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 Student(long id, String name, int age) { super(); this.id = id; this.name = name; this.age = age; } public String toString() { return name+"、"+id; } public static void main(String[] args) { Student d= new Student(30, "XXX", 20); System.out.println(d.toString()); } }

在修改试题中阅读

扫描二维码免费使用微信小程序搜题/刷题/查看解析。

版权声明:本文由翰林刷题小程序授权发布,如需转载请注明出处。

本文链接:https://20230611.cn/post/8440593.html