java编程 有没有人会这道题的 帮帮忙谢谢了

 我来答
漠轻桥
2020-04-17 · TA获得超过208个赞
知道小有建树答主
回答量:84
采纳率:0%
帮助的人:34.9万
展开全部
public class Student {

private String name;
private int score;

//无参构造方法
public Student() {
}
//有参构造方法
public Student(String name, int score) {
this.name = name;
this.score = score;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getScore() {
return score;
}

public void setScore(int score) {
this.score = score;
}

@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", score=" + score +
'}';
}
}
//测试类
public class StudentTest {

public static void main(String[] args) {
//使用无参构造方法
Student stu1 = new Student();
stu1.setName("student1");
stu1.setScore(100);
//使用有参构造方法
Student stu2 = new Student("student2", 99);
System.out.println("[输出学生1]" + stu1);
System.out.println("[输出学生2]" + stu2);
}
}
匿名用户
2020-04-17
展开全部
public class Student {
public static void main(String[] args) {
Student student1 = new Student();
student1.setName("李四");
student1.setScore(70);
Student student2 = new Student("张三", 80);
System.out.println(student1);
System.out.println(student2);
}

private String name;
private double score;

public Student(String name, double score) {
this.name = name;
this.score = score;
}

public Student() {
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public double getScore() {
return score;
}

public void setScore(double score) {
this.score = score;
}

public String toString() {
return "姓名: " + this.name + ", 成绩: " + this.score;
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xs_lzt
2020-04-17 · 帮你解决计算机基本问题
xs_lzt
采纳数:15 获赞数:16

向TA提问 私信TA
展开全部

class Student{

private String name;

private double score;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public double getScore() {

return score;

}

public void setScore(double score) {

this.score = score;

}

public Student() {}

public Student(String name, double score) {

super();

this.name = name;

this.score = score;

}

}


public class TestDemo {

public static void main(String[] args) {

Student stu1 = new Student();

stu1.setName("张三");

stu1.setScore(85);

System.out.println("姓名:"+stu1.getName()+",成绩:"+stu1.getScore());

Student stu2 = new Student("李四",90);

System.out.println("姓名:"+stu2.getName()+",成绩:"+stu2.getScore());

   }

}

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式