5、eoplezhangsan=newPeople(); intn=zhangsan.calculate("唱歌","跳舞","游泳"); system.out.println("有"+n+"个爱好");}16.4方法的值传递和引用传递值传递,传的是数值;而引用传递传的是对象(即相当于地址,和c里面的指针一样)java中为了避免引用传递出错,使用static关键字,使得对象无法二次赋值,而发生错误。 如:publicclass sanwei{ static int h;//长 static int
6、w;//重 static int k;//宽}public class Person{ int age; void speak(int age,sanweisw){ System. out.println( "我今年"+age+"岁了,我的三围是" +sw.h+"," +sw.w+"," +sw.k); age=24; sanwei. h=18; } publicstaticvoidmain(String[]args){ //
7、TODO Auto-generatedmethodstub Personxiaoming= new Person(); int age=22; sanweisw= new sanwei(); sw. h=90; sw. w=60; sw. k=90; //age传递的是值,而 sanwei传递的是引用(地址),c里面叫指针 xiaoming.speak(age,