We can't create objects of an abstract class, but we can create a List or an array of them. What is the difference?
Abstract class: is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class). Abstract method: can only be used in an abstract class, and it does not have a body. The body is provided by the subclass (inherited from).
abstract class a type of class that object can not be create it contain abstract or not abstract method while abstraction is mechanism of data hiding......... simply , abstract class implements abstraction for hiding complexity . Abstract class is a class with abstract methods & non abstract methods .
Abstract Class Vs. Interface: Explore the Difference between Abstract Class and Interface in Java. The Abstract class and Interface both are used to have abstraction. An abstract class contains an abstract keyword on the declaration whereas an Interface is a sketch that is used to implement a class.
A list or array is simply a place holder for a set of pointers, and you have NOT created instances of anything yet.
When you say Create Object - you mean create an instance - which you cannot do with an abstract class.
But you can create Lists or Arrays that point to them (and are EMPTY) - then you can move the pointers to 'real' instances of derived classes/objects
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With