File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes GenericServlet with constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "GenericServlet with constructor" Watch "GenericServlet with constructor" New topic

GenericServlet with constructor

Niranjan Prasad
Ranch Hand

Joined: Aug 13, 2005
Posts: 62
Why a Generic Servlet and HttpServlet has constructor even though they are abstract classes.?

Plse answer,this is an interview question
Sachin Dimble
Ranch Hand

Joined: Dec 07, 2005
Posts: 100
Hi Niranjan,
Every super class must have the constructor whether it is abstaract or non-abstract hence whenever instance of derived class get created before calling it's const. super class const get called. Now just try to corelect this concept with u r scenario will get the clerification.

Niranjan Prasad
Ranch Hand

Joined: Aug 13, 2005
Posts: 62
How is it possible,to create the object of super class which is an abstract
class,becoz super class's constructor is being called?
ak pillai
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
You cannot directly instatiate an abstract class, but you can instatiate it through a concrete class which extends your abstract class. Your abstract class becomes a part (means methods & attributes defined in your abstract class) of your concrete class instance.

java j2ee job interview questions with answers | Learn the core concepts and the key areas
Sachin Dimble
Ranch Hand

Joined: Dec 07, 2005
Posts: 100
Hey hey...u never instanctiate the abstract class,u just initialize the members of abstract class which gets inherited into derived class and in this case u can't say u have a instance of abstract class hence the memory allocation is for derived class and not for super...............!

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63529

Sachin Dimble, JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

Please read this for more information.

JavaRanch Sheriff

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: GenericServlet with constructor
It's not a secret anymore!