编写一段测试程序程序,生成Student类的两个对象,并输出每个对象的基本信息?
展开全部
public class Student { //定义一个学生类
private int StuNum; //学号
private int Name; //姓名
private char Sex; //性别
private int Age; //年龄
public Student(int StuNum, int Name, char Sex, int Age){//构造函数
this.StuNum = StuNum;
this.Name = Name;
this.Sex = Sex;
this.Age = Age;
}
public int getStuNum() { //获得学号
return StuNum;
}
public int getName() { //获得姓名
return Name;
}
public char getSex() { //获得性别
return Sex;
}
public int getAge() { //获得年龄
return Age;
}
public void setAge(int Age) { //修改年龄
this.Age = Age;
}
}
private int StuNum; //学号
private int Name; //姓名
private char Sex; //性别
private int Age; //年龄
public Student(int StuNum, int Name, char Sex, int Age){//构造函数
this.StuNum = StuNum;
this.Name = Name;
this.Sex = Sex;
this.Age = Age;
}
public int getStuNum() { //获得学号
return StuNum;
}
public int getName() { //获得姓名
return Name;
}
public char getSex() { //获得性别
return Sex;
}
public int getAge() { //获得年龄
return Age;
}
public void setAge(int Age) { //修改年龄
this.Age = Age;
}
}
展开全部
import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class Test {
@org.junit.Test
public void test() {
Student s1 = new Student("张三", 20);
Student s2 = new Student("李四", 21);
log.info(JSON.toJSONString(s1));
log.info(JSON.toJSONString(s2));
}
@Data
@AllArgsConstructor
class Student {
String name;
Integer age;
}
}
是这个意思吗
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class Test {
@org.junit.Test
public void test() {
Student s1 = new Student("张三", 20);
Student s2 = new Student("李四", 21);
log.info(JSON.toJSONString(s1));
log.info(JSON.toJSONString(s2));
}
@Data
@AllArgsConstructor
class Student {
String name;
Integer age;
}
}
是这个意思吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询