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( ):以姓名:联系电话的形式作为方法的返回值。
JAVA程序编写一个学生类Student
答案:4 悬赏:40
解决时间 2021-11-16 08:17
- 提问者网友:白柏唇蜜
- 2021-11-16 02:12
最佳答案
- 二级知识专家网友:冷眼_看世界
- 2021-11-16 02:45
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 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());
}
}
全部回答
- 1楼网友:说多了都是废话
- 2021-11-16 05:48
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+");
}
}
- 2楼网友:湫止没有不同
- 2021-11-16 05:27
//以下是程序段在自己机子上已经编译运行过了你自己试下
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());
}
}
- 3楼网友:浪女动了心
- 2021-11-16 04:21
咋不自己写呢
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯