class Demo_Student {
public static void main(String[] args) {
//创建对象
Student s = new Student();
//成员变量
s.name = "张三";
s.age = 23;
s.gender = "男人";
System.out.println(s.name + " " + s.age + " " + s.gender);
//成员方法
s.study();
s.sleep();
}
}
/*
*学生类
*属性:性别,年龄,名字
*行为:学习,睡觉
*/
class Student {
String name;
int age;
String gender;
public void study() {
System.out.println("学生学习");
}
public void sleep() {
System.out.println("学生睡觉");
}
}
|
|