1,class Demo2_Person {
public static void main(String[] args) {
Person p = new Person();
p.speak();
}
}
class Person {
String name;
int num;
public void speak() {
int num = 10;
System.out.println(name);
System.out.println(num);
}
}
2,class Demo1_Student {
Student s = new Student();
print(s);
}
public static void print(Student stu) {
stu.name = "张三";
stu.age = 23;
stu.speak();
}
}
为什么1用p.调用,2就print(s)调用? |
|