I read somewhere that we cannot initialize the interface, for example:
interface MyInterface{};
And the following code is definitely illegal:
MyInterface m = new MyInterface();
And as I recall, the text I read said: this is because the keyword is newused to allocate memory for class members; therefore, in the case of an interface, we have only abstract functions, therefore there is nothing to highlight in the interface; therefore, initialization of the interface is prohibited.
Well, that makes sense to me.
But in the case of an abstract class, we are allowed to declare and define abstract functions, not an abstract function, as well as ordinary variables, so why are we also not allowed to initialize an abstract class? And because of this, I was wondering when and how variables in an abstract class, if any, are allocated by memory?
source
share