「java设计学生一个类」用java语言创建一个学生类
本篇文章给大家谈谈java设计学生一个类,以及用java语言创建一个学生类对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
JAVA程序编写一个学生类Student
Public Class Student{
Public long id;
Public String name;
Public int age;
Public boolean sex;
Public long phone;
Public Student(long i,String n,int a,boolean s,long p){
this.id = i;
this.name = n;
this.age = a;
this.sex = s;
this.phone = p;
}
Public int getage(){
return this.age;
}
Public long getphone(){
return this.phone;
}
Public String toString(){
return this.name;
}
Public static void main(String[]args){
Student student = new Student(01,"李明",20,true,13xxx);
System.out.println(student.age());
System.out.println(student.getphone());
System.out.println(student.toString());
}
}
java定义一个学生类Student
1:
package wo;
-
public class StudentText{
public static void main(String[] args) {
Student s1=new Student(01,"张三");
Student s2=new Student(02,"李四");
boolean b=s1.equals(s2);
System.out.println(b);
}
}
class Student {
private int num;
private String nema;
public Student(int num, String nema) {
super();
this.num = num;
this.nema = nema;
}
public Student() {
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getNema() {
return nema;
}
public void setNema(String nema) {
this.nema = nema;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
if (num != this.num)
return false;
return true;
}
}
2
package wo;
public class polyTest {
public static void main(String[] args) {
penson p=new penson("张三",25);
System.out.println(p);
loyee l=new loyee(01,3000);
System.out.println(l);
Manager m=new Manager("老师");
System.out.println(m);
}
}
class penson{
private String name;
private int age;
public penson() {
super();
}
public penson(String name,int age) {
super();
this.name=name;
this.age=age;
}
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 String toString() {
return "penson [姓名:" + name + ",年龄:" + age + "]";
}
}
class loyee{
private int id;
private double salary;
public loyee() {
super();
}
public loyee(int id,double salary) {
super();
}
public int getID() {
return id;
}
public void setID(int iD) {
id = iD;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String toString() {
return "loyee [工号" + id + ", 工资:" + salary + "]";
}
}
class Manager{
private String type;
public Manager() {
super();
}
public Manager(String type) {
super();
this.type=type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String toString() {
return "Manager [职务名称:" + type + "]";}
}
java设计一个Student类
public class Student{
private String sName;
private String sClass;
private String sID;
Student(String sID,String sName)
{
this.sID = sID;
this.sName = sName;
}
Student(String sID,String sName,String sClass)
{
this(sID,sName);
this.sClass = sClass;
}
public String toString()
{
String ret = "";
if(sName != null)
{
ret = ret + sName;
}
if(sID != null)
{
ret = ret + "(" + sID + ",";
}else
{
ret =ret + "( ,";
}
if(sClass != null)
{
ret = ret + sClass + ")";
}else
{
ret = ret + " )";
}
return ret;
}
public String getsName() {
return sName;
}
public void setsName(String sName) {
this.sName = sName;
}
public String getsClass() {
return sClass;
}
public void setsClass(String sClass) {
this.sClass = sClass;
}
public String getsID() {
return sID;
}
public void setsID(String sID) {
this.sID = sID;
}
}
public class StudentDemo{
public static void main(String[] args)
{
Student[] st = new Student[5];
st[0] = new Student("student0","id0","class0");
st[1] = new Student("student1","id1","class1");
st[2] = new Student("student2","id2","class2");
st[3] = new Student("student3","id3","class3");
st[4] = new Student("student4","id4","class4");
for(int i = 0 ; i st.length; i++)
{
System.out.println(st[i].toString());
}
}
}
关于java设计学生一个类和用java语言创建一个学生类的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-11-21,除非注明,否则均为
原创文章,转载请注明出处。