getClass() 返回的是运行时类,即类A继承自B,那么A中无论调用this.getClass() 或者super.getClass() 返回的都是A的class
package test; public class BaseOut { public void out() { System.out.println("base out"+getClass().getSimpleName()); } }
package test; public class ExtentTest extends BaseOut { @Override public void out() { // TODO Auto-generated method stub super.out(); System.out.println("extent out"+getClass().getSimpleName()); } public static void main(String[] args) { new ExtentTest().out(); } }
返回结果 base outExtentTest extent outExtentTest
时间: 2024-10-27 17:15:33