top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Java: Why abstract class can't be instantiated?

+1 vote
864 views

Why abstract class can't be instantiated i.e. Object of abstract class can't be created??

posted Mar 4, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

An abstract type is defined largely as one that can't be created. You can create subtypes of it, but not of that type itself. The CLI will not let you do this.

An abstract class has a protected constructor (by default) allowing derived types to initialize it.

For example, the base-type Stream is abstract. Without a derived type where would the data go? What would happen when you call an abstract method? There would be no actual implementation of the method to invoke.

Def: 2

An Abstract class is a class that is declared as abstract. It may or may not include abstract methods.

We must declare Abstract class and Abstract methods with the key word abstract.

Abstract classes cannot be instantiated, means we can't create an object to Abstract class. We can create Subclasses to Abstract classes.

An Abstract class may or may not have abstract methods, abstract method in the sense a method can declared without any body implementation is called abstract method. So in that case JVM does not know how much memory it has to allocate for that abstract method because abstract method does not have body implementation. So JVM will not able to allocate memory for the abstract methods when the time of creating instance to Abstract class. So JVM unable to create the instance to Abstract class. So that we can't create the object for the Abstract class.

It is also possible that we can create an Abstract class with all concrete methods, that is without any abstract methods also. In that case also we can't create the instance for the Abstract class. Why because the abstract keyword simply indicates to JVM that the class cannot be instantiated.

The designers of Java made the JVM that when it find abstract keyword for any class then JVM can't create the instance for that class.

answer Mar 10, 2015 by Karthick.c
...