举例方法的形式参数是类名的调用
class Hello2 { public static void main(String[] args) { Student s = new Student(); print(s); } public static void print(Student stu) { stu.name = "张三"; stu.age = 23; stu.speak(); } } class Student { String name; int age; public void speak() { System.out.println(name + "..." + age); } }
结果: