为了账号安全,请及时绑定邮箱和手机立即绑定

Java报错 需要.class

Java报错 需要.class

临摹微笑 2018-07-09 15:12:43
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[]);//就是这一行提示需要.classByteArrayInputStream 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);}}}
查看完整描述

3 回答

?
qq_花开花谢_0

TA贡献1835条经验 获得超7个赞

objectOut.writeObject(Stu1);

查看完整回答
反对 回复 2018-07-19
  • 3 回答
  • 0 关注
  • 1021 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信