用java创建一个学生类,包括学号,姓名,成绩,然后构造方法,初始化,输出学生的基本信息
4个回答
展开全部
public class Student {
private String name;
private String number;
private int score;
public Student() {
}
public Student(String name, String number, int score) {
super();
this.name = name;
this.number = number;
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public String toString() {
return "Name: " + name
+ ",Number: " + number
+ ",Score : " + score;
}
//调用方法
public static void main(String[] args) {
Student s = new Student("Jack","123456",98);
System.out.println(s.toString());
}
}
运行结果:
Name: Jack,Number: 123456,Score : 98
追问
主类是啥
追答
Student,调用的方法只是一个测试的方法,如果你看不太懂建议先熟悉JAVA基础。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class student{
String id;
String name;
String record;
student(String id,String name,String record){
this.id=id;
this.name=name;
this.record=record;
}
public void show(){
System.out.println("学号:"+id+"/n 姓名:"+name+"/n 成绩"+record)
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
帮做10微信红包就可以,需要回复
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Student {
private String xuehao;
private String name;
private int score;
public Student(){}
public Student(String xuehao,String name,int score)
{
this.name=name;
this.score=score;
this.xuehao=xuehao;
}
public void speak()
{
System.out.println("学号:"+xuehao+",名字:"+name+",分数:"+score);
}
}
public class Test {
public static void main(String[] args) {
Student s = new Student("322088388", "小米",90);
s.speak();
}
}
private String xuehao;
private String name;
private int score;
public Student(){}
public Student(String xuehao,String name,int score)
{
this.name=name;
this.score=score;
this.xuehao=xuehao;
}
public void speak()
{
System.out.println("学号:"+xuehao+",名字:"+name+",分数:"+score);
}
}
public class Test {
public static void main(String[] args) {
Student s = new Student("322088388", "小米",90);
s.speak();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询