Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

nice q from jiris mock exam

 
Bhumika Thakkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which statements are TRUE regarding the following code? Mark

Please select two correct answers.



import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet extends GenericServlet {

public void init() { //1
// Do something
}

public void init(ServletConfig config) //2
throws ServletException{
// Do something
super.init(config); //3
}

public void destroy() { //4
// Do something
}

public void service(ServletRequest req, //5
ServletResponse res) {
// Do something
}
}

A : Method //1 is necessary for this code to compile
B : Method //2 is necessary for this code to compile
C : Line //3 is necessary for this code to run
D : Method //4 is necessary for this code to compile
E : Method //5 is necessary for this code to compile

ANSWER: C, E
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As the GenericServlet have a abstract service() method, It should be override by the extending Servlet.

The option C is correct. The Code will compile without this method call, but the ServletConfig object will not available. The Specification mandate when overriding this form of method, call super.init(config). Looking reasonable.

Thanks
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic