Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

nice q from jiris mock exam  RSS feed

 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!