This commit is contained in:
2024-10-10 09:19:56 +08:00
parent a3e84dc516
commit c34ef6f2c2
3 changed files with 61 additions and 35 deletions

View File

@@ -1,37 +1,37 @@
package chapter3;
class Student {
String name;
int age;
String sex;
void read() {
System.out.println("大家好,我是" + name + ",我在看书!");
}
void introduce() {
System.out.println("大家好,我叫" + name + ",我今年" + age + "岁了,我是" + sex + "");
}
}
public class Example01 {
public static void main(String[] args) {
Student s1 = new Student();
Student s2 = new Student();
s1.name = "小明";
s1.sex = "";
s1.age = 20;
s2.name = "小红";
s2.sex = "";
s2.age = 19;
s1.read();
s2.read();
s1.introduce();
s2.introduce();
}
}
//class Student {
// String name;
// int age;
// String sex;
//
// void read() {
// System.out.println("大家好,我是" + name + ",我在看书!");
// }
//
// void introduce() {
// System.out.println("大家好,我叫" + name + ",我今年" + age + "岁了,我是" + sex + "孩");
// }
//}
//
//public class Example01 {
// public static void main(String[] args) {
// Student s1 = new Student();
// Student s2 = new Student();
//
// s1.name = "小明";
// s1.sex = "男";
// s1.age = 20;
//
//
// s2.name = "小红";
// s2.sex = "女";
// s2.age = 19;
//
// s1.read();
// s2.read();
//
// s1.introduce();
// s2.introduce();
// }
//}