该程序定义了两个类,Person和Student,其中Student是Person的子类。程序的主方法中创建了一个Person对象和一个Student对象,并分别调用它们的printPerson()方法。

Person类中有一个私有方法getInfo(),返回字符串"Person",并有一个公有的printPerson()方法,输出调用该对象的getInfo()方法的结果。

Student类继承了Person类,并覆盖了其getInfo()方法,返回字符串"Student"。

因此,程序输出的结果为: Person Person

第一个输出是Person对象的getInfo()方法返回的结果,第二个输出是Student对象的printPerson()方法中调用的父类Person的getInfo()方法的结果。

解释程序每行代码的结果public class Test public static void mainString args new PersonprintPerson; new StudentprintPerson; class Student extends Person private String getInfo return Student; clas

原文地址: https://www.cveoy.top/t/topic/hqyM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录