父级引用指向对象
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author pengyl
* @date 2022/5/23 13:49
* @description TestClass
*/
public class TestClass {
@Test
public void test1() {
ChildClass c = new ChildClass();
c.print();
}
}
class BaseClass{
protected Logger logger = LoggerFactory.getLogger(this.getClass());
}
class ChildClass extends BaseClass {
public void print() {
logger.info("xxxxxxxxxxxxxxxx");
}
}
输出结果: