方法的形式参数是类名的时候如何调用:
形式参数:方法的参数列表中的参数
实际参数:调用方法时,传递的参数
基本数据类型:
形式参数的改变 对 实际参数没有影响
引用数据类型:
形式参数的改变 对 实际参数 有影响
class类型的参数,也属于引用数据类型
调用方式如下:
class Student {
public void study(){
System.out.println("正在复习中");
}
}
class Test {
public static void main(String[] args){
//创建Test对象
Test t = new Test();
Student s = new Student();
t.method( s );
}
public void method( Student s ){
//this --> t对象
s.study();
}
} |
|