a) 字段成员ID:表示学号;
b) 字段成员Name:表示姓名;
c) 无参构造函数;
d) 带参数的构造函数,其中参数用来初始化类实例中的ID和Name字段成员;
e) 输出自身字段成员信息的方法,方法名为Output;
在main方法中定义Student变量,并它引用该类的实例。通过该变量调用Output方法输出人员信息。
java定义Student类,让它表示学生类,该类的成员包括
答案:2 悬赏:80 手机版
解决时间 2021-03-02 09:24
- 提问者网友:箛茗
- 2021-03-02 02:20
最佳答案
- 五星知识达人网友:千杯敬自由
- 2021-03-02 03:01
public class Student {
private int ID;
private String Name;
public Student() {
super();
}
public Student(int iD, String name) {
super();
ID = iD;
Name = name;
}
public void Output()
{
System.out.println("人员信息:姓名:"+this.Name+",ID"+this.ID);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Student stu=new Student(123,"张三");
stu.Output();
}
}
private int ID;
private String Name;
public Student() {
super();
}
public Student(int iD, String name) {
super();
ID = iD;
Name = name;
}
public void Output()
{
System.out.println("人员信息:姓名:"+this.Name+",ID"+this.ID);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Student stu=new Student(123,"张三");
stu.Output();
}
}
全部回答
- 1楼网友:duile
- 2021-03-02 03:36
package com.yourname;
public class student {
private string sno;
private string sname;
private string ssex;
private int sage;
private float sjava;
public student()
{
}
public student(string sno, string sname, string ssex, int sage, float sjava) {
super();
this.sno = sno;
this.sname = sname;
this.ssex = ssex;
this.sage = sage;
this.sjava = sjava;
}
public string getsno() {
return sno;
}
public void setsno(string sno) {
this.sno = sno;
}
public string getsname() {
return sname;
}
public void setsname(string sname) {
this.sname = sname;
}
public string getssex() {
return ssex;
}
public void setssex(string ssex) {
this.ssex = ssex;
}
public int getsage() {
return sage;
}
public void setsage(int sage) {
this.sage = sage;
}
public float getsjava() {
return sjava;
}
public void setsjava(float sjava) {
this.sjava = sjava;
}
public static void main(string[] args) {
student stua = new student();
stua.setsno("cs09877976");
stua.setsname("student a");
stua.setssex("male");
stua.setsage(19);
stua.setsjava(80.0f);
student stub = new student("cs09877977", "student b", "female", 20, 100.0f);
system.out.println("stua [no=" + stua.getsno() + ",name="
+ stua.getsname() + ",sex=" + stua.getssex() + ",age="
+ stua.getsage() + ",java=" + stua.getsjava() + "]");
system.out.println("stub [no=" + stub.getsno() + ",name="
+ stub.getsname() + ",sex=" + stub.getssex() + ",age="
+ stub.getsage() + ",java=" + stub.getsjava() + "]");
// outputs:
// stua [no=cs09877976,name=student a,sex=male,age=19,java=80.0]
// stub [no=cs09877977,name=student b,sex=female,age=20,java=100.0]
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯