Bootstrap

java定义一个学生类_编写一个JAVA程序片断 定义一个表示学生的类student

编写一个JAVA程序片断定义一个表示学生的类student,包括域"学号","班级","姓名","性别","年龄";方法"获得学号","获得班号","获得姓名","获得性别","获得年龄","修改年龄".

程序如下:

import http://www.doczj.com/doc/0a81347ca26925c52cc5bf45.htmlng.String;

import http://www.doczj.com/doc/0a81347ca26925c52cc5bf45.htmlng.System;

import java.io.*;

public class StudentManage

{

public static void main(String args[])

{

Student myStudent=new Student(1234567,"023","hfx","male",21);

System.out.println(myStudent.toString());

}

}

class Student

{

long studentNumber;

String classNumber;

String studentName;

String studentSex;

int studentAge;

Student(long a,String s,String d,String f,int h)

{

studentNumber=a;

classNumber=s;

studentName=d;

studentSex=f;

studentAge=h;

}

void getNumber(long sno,String sna)

{

if(studentName==sna)

studentNumber=sno;

else

System.exit(1);

}

;