I understand:
Because an Abstract Class is a skeleton structure(an incomplete construct if you may), hence the term Abstract.
abstract class Person(){
abstract void Speak();
}
Means every Person
must speak. That means every person should know how to speak (implement the speak()
). new Person()
cannot have that, so it is not allowed.
In java, everything is represented as an object except a few cases. When you are about to instantiate the class (A blueprint), you must know the exact size of the class member variables, member methods, and the constructors. Since some/all of the methods are abstract, and JVM doesn't know the size. Hence allocating memory is useless.
But We can implement something to overcome this problem If we take the memory allocation part away from the JVM and assign this ownership to the USER.
The reason why Java doesnt allows an abstract class to be instantiated is logical. We haven't given the definition of a method and therefore, if it had allowd the creation of the object, there was no return address to pop the function from the stack and we get thus, stuck. Thus, its logical only not to allow the object instattion.
very simple reason jvm playing to restrict us to instantiate abstract class and interface.
Assume compiler allow us to instantiate both ok.
So suppose my abstract class contains 5 abstract method means only method prototype no method body.
So as we know every method call creating a separate stack in jvm Java stack area That memory allocation happened based on method structure and after execute that stack is destroying right.
So if my method is not contains any body means how can jvm predict memory to allocate that method
Second if no body means no method execution so never it will destroy from your Java stack area there may be a chance u can get memoryout error.
So to consider these 2 case compiler restrict us to instantiate both interface and abstract class