题目:实验4: 校内报纸 程序模板 请按模板要求,将【代码】替换为Java程序代码。 //RedCowForm.java public class School { String schoolName; 【代码1】 //声明一个InnerNewsPaper 类型的变量newsPaper School() { this("某某大学"); //调用带参数的构造方法 } School(String s) { 【代码2】//使用new关键字创建对象newsPaper String [] content = {"学校举办迎新会.", "机械系获得机器人大赛冠军.", "计算机学院召开学生会换届大会."}; schoolName = s; newsPaper.setContent(content); } public void showNews(){ newsPaper.showContent(); } class InnerNewsPaper { String [] content; String paperName = "校新闻周报"; void setContent(String []s){ content = s; } public void showContent(){ System.out.println(schoolName); for(int i=0;i System.out.println(content[i]); } } } } //MainClass.java public class MainClass { public static void main(String args[]) { School school = new School("创新大学"); school.showNews(); } }
答案:评论后可见此内容