public static void main(string[] args) {// 1、创建多个各类新闻标题对象ne
时间: 2024-04-14 20:31:28 浏览: 125
Visostudio+C#.NET+动态链接库代码示例
wsTitle1 = new NewsTitle("Sports", "Lionel Messi wins FIFA Ballon d'Or");
NewsTitle newsTitle2 = new NewsTitle("Technology", "Apple unveils new iPhone 13 with 5G support");
NewsTitle newsTitle3 = new NewsTitle("Entertainment", "Taylor Swift releases new album 'Red (Taylor's Version)'");
NewsTitle newsTitle4 = new NewsTitle("Politics", "President Biden signs infrastructure bill into law");
// 2、将新闻标题对象添加到一个列表中
List<NewsTitle> newsTitlesList = new ArrayList<>();
newsTitlesList.add(newsTitle1);
newsTitlesList.add(newsTitle2);
newsTitlesList.add(newsTitle3);
newsTitlesList.add(newsTitle4);
// 3、遍历列表并打印新闻标题
for (NewsTitle newsTitle : newsTitlesList) {
System.out.println(newsTitle.getCategory() + ": " + newsTitle.getTitle());
}
}
阅读全文