方法的形式参数是类名的时候如何调用

举例方法的形式参数是类名的调用

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);
    }
}

结果:

原文地址:https://www.cnblogs.com/Wangzui1127/p/11299779.html