学生类Student中有属性account和password,还有包含两个参数的构造方法,
已知学生信息为:FXStudent s1=new FXStudent("admin","123456");
FXStudent s2=new FXStudent("guest","654321");
请完成统计学生对象数量的程序代码.
public class FXStudent {
private String account;//姓名
private String password;//密码
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public FXStudent(String account,String password) {
this.account=account;
this.password=password;
}
}
测试程序
import java.util.ArrayList;
public class FXStudentTest {
public static void main(String[] args) {
//泛型:参数化类型,操作的数据类型被定义为一个参数,并且参数类型可以用在类,接口,方法的创建中
ArrayList a=new ArrayList();//定义了一个FXStudent类型
FXStudent s1=new FXStudent("admin","123456");
FXStudent s2=new FXStudent("guest","654321");
a.add(s1);//向ArrayList中添加数据
a.add(s2);
System.out.println("学生对象的数量:"+a.size());//size()用于获取泛型集合有多少个元素,
//length()方法:用于获取字符串和数组长度;
}
}



