Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Can we write a constructor for a Servlet class ? if yes how ?
if no why not ?

Answers were Sorted based on User's Feedback



Can we write a constructor for a Servlet class ? if yes how ? if no why not ?..

Answer / sekhar babu

yes, we can write constructor on our own but it should be
no argument public constructor only, cause container will
create the object so it needs no argument constructor.

Is This Answer Correct ?    22 Yes 1 No

Can we write a constructor for a Servlet class ? if yes how ? if no why not ?..

Answer / abhishek taneja

yes offcourse you can write a constructor for a servlet
after all it is a java class. you can simply provide but if
u do not provide then it is by default include the no
argument constructor that is used by the Init() method in
the servlet life cycle.

Is This Answer Correct ?    11 Yes 0 No

Can we write a constructor for a Servlet class ? if yes how ? if no why not ?..

Answer / tharun raj

yes, we can provide a constructor in servlet calss..
Webcontainer uses the similar code shown below for creating
servlet object for our servlet class

Class c=Class.forName("OurServlet");
Object o=c.newInstance();

this newInstance() method uses zero argument constructor
while creating object..

Is This Answer Correct ?    10 Yes 0 No

Can we write a constructor for a Servlet class ? if yes how ? if no why not ?..

Answer / chandra

constructor required, but it should be public no-argument
constructor. even though if you are not write that
constructor java compiler will create that construtctor by
default. for that your servlet class should be public other
wise you will get RuntimeWxception saying RequestedResource
is not available like that.

Is This Answer Correct ?    9 Yes 2 No

Can we write a constructor for a Servlet class ? if yes how ? if no why not ?..

Answer / n.l.narayana

yes., when ever the servlet is executed .,it requires
configuration.,the configuration should be done in init()
method only.,

Is This Answer Correct ?    4 Yes 0 No

Can we write a constructor for a Servlet class ? if yes how ? if no why not ?..

Answer / saikiran

that is one of the specification rule that
1.instantiated by constructior with no argument.
2.implementd class should be public and non-abstract.
3.should be implemnt javax.servlet.Servlet
We can Write it

Is This Answer Correct ?    2 Yes 0 No

Can we write a constructor for a Servlet class ? if yes how ? if no why not ?..

Answer / narayana rao dasari

yes.....! we can write constructor for servlet class why
because every java class allows construction initialization
if we do not write constructor explicitly it will call
default constructior.

If we call our own constructiors means we will not able to
access the servelet config objects so better wat is to
intializeing in init() method......thank u,
Narayan

Is This Answer Correct ?    2 Yes 0 No

Can we write a constructor for a Servlet class ? if yes how ? if no why not ?..

Answer / abc

you can write as like for regular class.

Is This Answer Correct ?    10 Yes 12 No

Can we write a constructor for a Servlet class ? if yes how ? if no why not ?..

Answer / ravikiran

we cann't write a constructor because the servlet container
will create the instance of the servlet by calling the
no-arg constructor

Is This Answer Correct ?    1 Yes 8 No

Can we write a constructor for a Servlet class ? if yes how ? if no why not ?..

Answer / ravi

No..not at all,,,,servlet is a class which is dynamically
loaded...dynamically loaded class never requires
constructors.

Is This Answer Correct ?    8 Yes 18 No

Post New Answer

More Servlets Interview Questions

Differentiate between the print writer and servlet output stream?

0 Answers  


What is the use of attribute in servlets?

0 Answers  


What must be implemented by all servlets?

0 Answers  


What are the phases of a servlet life cycle?

0 Answers  


My Question is that i am using <image> tag in my servlet and after compilation after that calling by url in my browser then images are not showing. Sometime images are showing and sometime is not showing. I am using Tomcat to run my servlets. Tell me if there any specification for image in servlets or what is solution for this ??

2 Answers  


What is pure servlet?

0 Answers  


what is the advantage of using Servlets over CGI programming?

4 Answers  


The code in a finally clause will never fail to execute, right?

0 Answers  


Can you refresh servlet in client and server-side automatically?

0 Answers  


What are the security issues in Servlets?

2 Answers  


What is use of parseQueryString ?

1 Answers  


Explain the different ways for servlet authentication?

0 Answers  


Categories