回答:抽象类是可以继承实体类,但前提是实体类必须有明确的构造函数。
但是我试了一下,可以正常打印结果。这是咋回事?
import org.junit.Test;
/**
* @author yyc
*
*/
public class TestAbstractExtendsEntity {
@Test
public void TestAbstractExtendsEntity() {
Abstract b = new A();
b.helloWorld();
}
class A extends Abstract {
}
abstract class Abstract extends Entity {
}
class Entity {
private Entity() {
}
public void helloWorld() {
System.out.println("hello entity2");
}
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
代码上可以这样写,不代表你应该这样做。
凭啥不应该正常打印结果呢?这代码没啥问题啊