定义一个学生类
成员变量:姓名,年龄,性别
方法变量:学习,吃饭,睡觉
*/
class StudentTest
{
public static void main(String[]args)
{
Student s = new Student();
s.sleep();
s.study();
s.eat();
s.age = 20;
s.name ;
s.sex ;
System.out.print(s.name+"*****"+s.age+"*****"+s.sex);
}
}
class Student
{
String name;
int age;
char sex;
public void study()
{
System.out.println("学习");
}
public void eat()
{
System.out.println("吃饭");
}
public void sleep()
{
System.out.println("睡觉");
}
} |
|