- public class Student{
- private String name; //全局变量也叫成员变量
- private Integer age;
- private float score;
- public Student(String name,Integer age,float score)
- {
- this.age=age;
- this.name=name;
- this.score=score;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public Integer getAge() {
- return age;
- }
- public void setAge(Integer age) {
- this.age = age;
- }
- public float getScore() {
- return score;
- }
- public void setScore(float score) {
- this.score = score;
- }
复制代码 在类的内部,方法的外部声明的变量叫做成员变量也叫全局变量。如以上代码中的name,age,score属性。 |