Java language programming:定义学生类

题目:<1>.定义一个学生类:
属性:姓名(name)、年龄(age)、性别(sex)、分数(score)
方法:招呼(greeting)、打印学员信息(information)
<2>.创建多个学生对象,并且为其各个属性赋值,并且调用方法。

定义:

package baggage.java;
public class Student {
    String name;//属性
    String sex;
    int score;
    int age;
  public void greeting(){
      System.out.println(name+":Hi!");
  }
  public void information() {
     System.out.println(name+"--"+age+"--"+sex+"--"+score);
  }
}

调用:

package baggage.java;
public class TestStudent {
    public  static void main(String[] args){
        Student student =new Student();
        student.name="丧彪";
        student.sex="男";
        student.age=45;
        student.score=98;
        student.greeting();
        student.information();

        Student s1 =new Student();
        s1.name="卡拉咪";
        s1.sex="男";
        s1.age=20;
        s1.score=99;
        s1.greeting();
        s1.information();
    }
}

你可能感兴趣的:(java,开发语言)