中易网

JAVA程序编写一个学生类Student

答案:4  悬赏:40  
解决时间 2021-11-16 08:17
1)学生类Student属性有:
id;long型,代表学号
name;String类对象,代表姓名
age;int型,代表年龄
sex;boolen型,代表性别
(其中:true表示男,false表示女)
phone;String类对象,代表联系电话
(2)学生类方法有:
Student(long i,String n,int a,boolean s,long p):有参构造函数,形参表中的参数分别初始化学号、年龄、性别和联系电话。
int getAge()( ):获取年龄作为方法的返回值。
long getphone( ):获取联系电话作为方法的返回值。
public String toString( ):以姓名:联系电话的形式作为方法的返回值。
最佳答案
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());
}
}
全部回答
public class student{ private string name; private int xh; public student(){} public student(string name, string xh){ this.name = name; this.xh = xh; } public string getname(){ return name; } public string getxh(){ return xh; } public void setname(string name){ this.name = name; } public void setxh(string xh){ this.xh = xh; } public void print(){ system.out.println("my name is "+name+",xh is"+xh+"); } }
//以下是程序段在自己机子上已经编译运行过了你自己试下 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,8888); System.out.println(student.getage()); System.out.println(student.getphone()); System.out.println(student.toString()); } }
咋不自己写呢
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
上海朱家角小镇游玩
厦门杏林到海沧新埯公交车有吗?要做多少路
在拉升过程中,主力是怎么把散户洗出去的
银通园区派出所地址有知道的么?有点事想过去
四川省乐山市沙湾区有什么好玩的地方?
向永州市公安局纪委反映永州市零陵区分局干警
江苏交广汽车装潢服务部地址在哪,我要去那里
我在重庆考的施工员证能不能拿回贵州去用?
经济开发区派出所地址在什么地方,想过去办事
六哲的QQ是什么啊?要真实的!非成勿写!
小米led随身灯怎么样
洪相派出所办公地址在什么地方,我要处理点事
请问哺乳期吃苋菜会导致回奶吗?
求蒙牛牛奶具体营养成分表(做实验用,要具体
落距17米锤重18吨,夯击能量是多少
推荐资讯
负离子电吹风真的有用吗?想买个。不知道原理
老人老是脚痒怎么回事
我的纹身纹了有俩天了,可是不知道怎么的,纹
东谭社区居委会地址在什么地方,想过去办事
学院奖如何看作品上传是否成功?
舌苔厚腻怎么办?
摊子口有没有好吃的火锅?
怀孕期间晚上睡觉总感觉热有问题吗?
重做系统后USB2.0端口不能用,只能充电,只有3
在汽车车身上帖汽车贴纸交警罚款吗?
怎样能把阳台改造儿童房?
您好,9岁的孩子可以吃牛初乳吗
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?