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

如下所示,求教关于JAVA对象循环引用的问题~

如下所示,求教关于JAVA对象循环引用的问题~

一只萌萌小番薯 2021-11-19 15:11:41
import java.io.*;public class collect {/*** @param args*/public static void main(String[] args) throws Exception {// TODO Auto-generated method stubFile f=new File("c:\\france.txt");RandomAccessFile mm = new RandomAccessFile(f,"rw");Item[] qq= new Item[1000];for (int i = 0; i < 1000; i++) {qq[i] = new Item();}for (int h = 0; h < 10; h++) {qq[h].title=mm.readLine();qq[h].content=mm.readLine()+"\n"+mm.readLine()+"\n"+mm.readLine();qq[h].getInfo();}}class Item{String title;String content;public void getInfo(){System.out.println(title);System.out.println(content);}}刚刚学,上面搞来搞去不知道错哪了.....路过帮帮忙
查看完整描述

2 回答

?
holdtom

TA贡献1805条经验 获得超10个赞

import java.io.*;
public class Collect {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
File f=new File("c:\\france.txt");
RandomAccessFile mm = new RandomAccessFile(f,"rw");
Item[] qq= new Item[1000];
for (int i = 0; i < 1000; i++) {
qq[i] = new Item();
}
for (int h = 0; h < 10; h++) {
qq[h].title=mm.readLine();
qq[h].content=mm.readLine()+"\n"+mm.readLine()+"\n"+mm.readLine();
qq[h].getInfo();
}
}
}//此处再加一个大括号,并且不能在最后加大括号,除非你把下面的类当成静态内部类

class Item{
String title;
String content;
public void getInfo(){
System.out.println(title);
System.out.println(content);
}
}



查看完整回答
反对 回复 2021-11-23
?
波斯汪

TA贡献1811条经验 获得超4个赞

class Item{ 的前面少了一个“}”

查看完整回答
反对 回复 2021-11-23
  • 2 回答
  • 0 关注
  • 214 浏览

添加回答

举报

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