猿问

Java报错 需要.class

import java.io.*;
class Students implements Serializable{
String name=null;
double grade;
Students(String name,double grade){
this.name=name;
this.grade=grade;
}
public void setGrade(double grade){
this.grade=grade;
}
public void setName(String name){
this.name=name;
}
public double getGrade(){
return grade;
}
public String getName(){
return name;
}
}
public class likecool{
public static void main(String[] args) {

Students Stu1[]={new Students("小明",100),new Students("小红",0)};

try{ ByteArrayOutputStream out= new ByteArrayOutputStream();
ObjectOutputStream objectOut=new ObjectOutputStream(out);
objectOut.writeObject(Stu1[]);//就是这一行提示需要.class
ByteArrayInputStream in=new ByteArrayInputStream(out.toByteArry());
ObjectInputStream objectIn=new ObjectInputStream(in);
Students Stu2[]=objectIn.readObject();
System.out.println("学生的姓名和成绩:");
for (int i=0;i<Stu2.length;i++)
System.out.println(Stu2[i].getName(),Stu2.getGrade());
}
catch(Exception event){
System.out.print(event);
}
}
}

临摹微笑
浏览 1022回答 3
3回答

qq_花开花谢_0

objectOut.writeObject(Stu1);
随时随地看视频慕课网APP
我要回答