Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GenericServlet with constructor

 
Niranjan Prasad
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

-Sachin
 
Niranjan Prasad
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...............!

-Sachin.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

thanks,
bear
JavaRanch Sheriff
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic