• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

related to Abstract class

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic