You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
987 B
27 lines
987 B
import java.io.IOException;
|
|
import java.util.List;
|
|
|
|
// 测试类:验证继承+多态效果
|
|
public class CrawlerTest {
|
|
public static void main(String[] args) throws IOException {
|
|
// 多态核心:父类引用指向子类对象
|
|
BaseMovieCrawler crawler = new MovieCrawler();
|
|
|
|
// 爬取前5部电影
|
|
List<Movie> movies = crawler.crawl(5);
|
|
|
|
System.out.println("\n=== 爬取结果 & 多态测试 ===");
|
|
for (Movie movie : movies) {
|
|
// 多态调用:同一个play()方法,不同子类表现不同行为
|
|
movie.play();
|
|
}
|
|
|
|
// 单独测试两个子类的多态
|
|
System.out.println("\n=== 子类多态单独测试 ===");
|
|
Movie theatreMovie = new TheatreMovie("流浪地球2", 2023, 9.3, "科幻", 59.9);
|
|
Movie animatedMovie = new AnimatedMovie("哪吒之魔童降世", 2019, 9.6, "动画", "可可豆动画");
|
|
|
|
theatreMovie.play();
|
|
animatedMovie.play();
|
|
}
|
|
}
|