• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Abstract Class Constructor

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abstract Class cannot be instantiated,then y abstract classes are
provided with constructors?
For example GenericServlet and HttpServlet have constructors?

Plse answer this,this is an interview question
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
think about subclasses of abstract clases. the abstract class might want to gurantee some initialisation process, or even some constructor functionality.

"constructor" chaining would be the keyword.

but i'd say that only protected abstract constructors make sense... :-)

many greetings,
jan
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And please don't post the same question into several forums. You've already asked this in the Servlet forum.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even if an abstract class cannot be directly instantiated it must still be initialized and have a constructor executed when a subclass is instantiated. This is precisely why any class without a visible constructor cannot be subclassed. In most cases this translates to "a class without a non-private constructor cannot be subclassed", however there's an exception and that is when the subclass is in the same compilation unit. Regardless, the point is that to create an instance of a class, whether it's abstract or not, it must be initialized and a constructor must be executed.
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic