public class Test8 {
public static void main(String[] args)
{//创建学生对象
Student stu=new Student("张三",22,95);
stu.sop();
}
}
class Student
{private String name;
private int age;
private int score;
//给对象初始化,开始就有姓名,年龄,评分
Student(String name,int age,int score)
{this.name=name;
this.age=age;
this.score=score;
}
//设置姓名,年龄,评分 获取姓名,年龄,评分
public void setName(String name)
{
this.name=name;
}
public String getName()
{
return name;
}
public void setAge(int age)
{
this.age=age;
}
public int getAge()
{
return age;
}
public void setScore(int score)
{
this.score=score;
}
public double getScore()
{
return score;
}
//提供一个打印方法
public void sop()
{
System.out.println("name="+name+" age="+age+" score="+score);
}
}
|
|