ProAnswers.org

why don't create object of Abstract class?

why don’t create object of Abstract class n Interface in java?

1 Like

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.

The short answer: because that’s how they are defined.

Definitions...

Instantiate - to create one instance of a class. The newly created object is a "kind of" the class.

Interface - a declaration of methods that are expected of a class. If the class declares they implement the interface, it must provide implementations for all the methods declared by the interface.

Abstract Class - a class that cannot be instantiated. Often it will include one or more methods that are also declared abstract and must be implemented by subclasses for the subclass to be concrete (opposite of abstract), and therefore able to be instantiated. Does not have to include abstract methods; the documentation may otherwise specify what is required of a valid concrete subclass.

The reason behind this is , the abstract class contains
abstract methods which cant do any job. Calling such
function is meaningless. So it is not allowed to
instantiate abstract class

Because it’s abstract and an object is concrete. An abstract class is sort of like a template, or an empty/partially empty structure, you have to extend it and build on it before you can use it.

	Take for example an "Animal" abstract class. There's no such thing as a "pure" animal - there are specific types of animals. So you can instantiate Dog and Cat and Turtle, but you shouldn't be able to instantiate plain Animal - that's just a basic template. And there's certain functionality that all animals share, such as "makeSound()", but that can't be defined on the base Animal level. So if you could create an Animal object and you would call makeSound(), how would the object know which sound to make?