定义一个学生类Student,具体要求如下: 1)私有字段姓名name(string)、
定义一个学生类Student,具体要求如下:1)私有字段姓名name(string)、性别sex(char)、年龄age(int)和学号no(string)等信息;2)具...
定义一个学生类Student,具体要求如下: 1)私有字段姓名name(string)、性别sex(char)、年龄age(int)和学号no(string)等信息; 2)具有姓名Name、性别S
展开
1个回答
展开全部
public class Test {
public static void main(String[] args) {
Student s = new Student("Name",'S',18,"10001");
s.showInfo();
}
}
class Student{
private String name;
private char sex;
private int age;
private String no;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public Student(String name,char sex,int age,String no){
this.name=name;
this.sex=sex;
this.age=age;
this.no=no;
}
public void showInfo(){
System.out.println("姓名:"+name+">性别:"+sex+">年龄:"+age+">编号:"+no);
}
}
是这样的效果吗?希望能帮到你!
public static void main(String[] args) {
Student s = new Student("Name",'S',18,"10001");
s.showInfo();
}
}
class Student{
private String name;
private char sex;
private int age;
private String no;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public Student(String name,char sex,int age,String no){
this.name=name;
this.sex=sex;
this.age=age;
this.no=no;
}
public void showInfo(){
System.out.println("姓名:"+name+">性别:"+sex+">年龄:"+age+">编号:"+no);
}
}
是这样的效果吗?希望能帮到你!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询