日期:2014-05-20 浏览次数:20655 次
public class Student { private String Name; private double English; private double Math; public Student(){ } public Student(String Name,double English,double Math){ this.Name=name; this.English=English; this.Math=Math; } }
------解决方案--------------------
public class Student { private String name; private double english; private double math; //封装变量 public String getName() { return name; } public void setName(String name) { this.name = name; } public double getEnglish() { return english; } public void setEnglish(double english) { this.english = english; } public double getMath() { return math; } public void setMath(double math) { this.math = math; } //无参构造函数 public Student(){} //重载构造函数 public Student(String name , double english , double math){ this.name= name; this.english =english; this.math = math; } }
------解决方案--------------------
public class Student { private String name; //姓名 private double english;//英语成绩 private double math;//数学成绩 //getter and setter 方法 public String getName() { return name; } public void setName(String name) { this.name = name; } public double getEnglish() { return english; } public void setEnglish(double english) { this.english = english; } public double getMath() { return math; } public void setMath(double math) { this.math = math; } /** * 默认构造函数 */ public Student() { } /** * 3个参数构造函数 * @param name * @param english * @param math */ public Student(String name, double english, double math) { this.name = name; this.english = english; this.math = math; } /** * 重写toString方法 */ @Override public String toString() { return "Student [name=" + name + ", english=" + english + ", math=" + math + "]"; } /** * 测试main方法 * @param args */ public static void main(String[] args) { System.out.println(new Student("张三 " ,85.5, 90).toString()) ; } }