Formal parameter method is how the class name when calling

 

Examples formal parameter method is to call the class name

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

 

result:

 

Guess you like

Origin www.cnblogs.com/Wangzui1127/p/11299779.html