File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Abstract class also has constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract class also has constructor" Watch "Abstract class also has constructor" New topic
Author

Abstract class also has constructor

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

If we cannot instantiate an abstract class, why does it have a constructor. We are obviously never going to create an object of an abstract class, but only of its sub classes. Correct? Then what is the purpose of having it there at all? Is it just to accommodate the Java language statute that since first statement in any constructor is a call to super() , it has to be there? Or is there something more to it?


~ Mansukh
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Constructors don't create objects. They put a newly created object into a valid initial state. Since abstract classes can have state (member variables), they need constructors to initialize that state.



How would we initialize the common base class state "name" without the constructor?
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Jeff Verdegan wrote:Constructors don't create objects. They put a newly created object into a valid initial state.


If constructors are not responsible for creating objects in Java, then what is?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Mansukhdeep Thind wrote:
Jeff Verdegan wrote:Constructors don't create objects. They put a newly created object into a valid initial state.


If constructors are not responsible for creating objects in Java, then what is?


The new operator, most of the time.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Jeff Verdegan wrote:
Mansukhdeep Thind wrote:
Jeff Verdegan wrote:Constructors don't create objects. They put a newly created object into a valid initial state.


If constructors are not responsible for creating objects in Java, then what is?


The new operator, most of the time.


OK Jeff. Thank you. I shall close this thread now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstract class also has constructor
 
Similar Threads
doubt in abstract class
Abstract class
interface is nothing but a pure abstract class. why interface does not has constructor
Constructor
Can i have a private constructor in an abstract class