File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes related to Abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "related to Abstract class" Watch "related to Abstract class" New topic
Author

related to Abstract class

padmaratna kamble
Greenhorn

Joined: Apr 26, 2006
Posts: 26
Hi,
I want to know Abstract class has constructor but we can not initiate. why?
and why interface not have constructor?
please help me.
Thanks in advance.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24057
    
  13

An abstract class can have instance variables; the purpose of a constructor is to initialize member variables. Although you can't instantiate an abstract class directly, every subclass of that abstract class must call one of the abstract class's constructors from its own constructors; this give the abstract class a chance to initialize its members.

An interface can't have a constructor, as you say. Since an interface cannot have any instance variables, a constructor would serve no purpose. In any case, an interface can't contain any member methods at all, so of course it can't have constructors either.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: related to Abstract class
 
Similar Threads
class Math is concrete class but still it cannot be instantiated.
doubt in abstract class
interface is nothing but a pure abstract class. why interface does not has constructor
what is the use of constructor inside abstract class
java.awt.Component