2022年12月11日对象作为参数的方法

在这里插入代码片
```public class Student {
	int id,age;
	String name;
	int score;
	public void show() {
		System.out.println("学号:"+id+"\n姓名:"+name+"\n尺码:"+score);
	}

}
//下面的是第二个类
在这里插入代码片
public class Studentss {
	Student[] gs=new Student[2];
	Student gg=new Student();
	public void test(Student stu[]) {
		gg.id=10;
		gg.name="王紫";
		gg.score=99;
		gg.age=18;
		gs[0]=gg;
		Student gg2=new Student();
		gg2.id=11;
		gg2.age=19;
		gg2.name="好甜";
		gg2.score=60;
		gs[1]=gg2;	
		for(int i=0;i<gs.length;i++) {
System.out.println(gs[i].id+"\t"+gs[i].name+"\t"+gs[i].age+"\t"+gs[i].score);
	}
	}
}
//下面的是主方法类进行测试

```java
在这里插入代码片
```public static void main(String[] args) {
		// TODO 自动生成的方法存根
		Student[] gs=new Student[2];
		Studentss su=new Studentss();
		Student gg=new Student();
		gg.id=10;
		gg.name="王紫";
		gg.score=99;
		gg.age=18;
		gs[0]=gg;
		Student gg2=new Student();
		gg2.id=11;
		gg2.age=19;
		gg2.name="好甜";
		gg2.score=60;
		gs[1]=gg2;
		System.out.println("本班学生列表:\n");
		su.test(gs);
		
		
	}
//因为我之前用的是两种方法所以还有些多余的
}



你可能感兴趣的:(java,c++,算法)