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

Doubt in Mock Question

 
Pawan Ramchandani
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question i found at jdiscuss they says ans.1,3 is correct.
My question is that if i am not passing any value for price so it will be null so the null can not be convert in to int then it should give exception.
pls. clear my doubt.

Problem

Consider the following code of a JavaBean:
public class TicketBean
{
int price;
String name;
// assume usual getters and setters.
}

Now, consider this ticketview.jsp page code:

<html><head></head><body>
<jsp:useBean id="ticket" class="TicketBean"/>
<jsp:setProperty name="ticket" property="*"/>
Name : <%=ticket.getName()%>
Price : <%=ticket.getPrice()%>
</body>
<html>

Which of the following lines will be in the output of the JSP page, if it is accessed through URL:
http://servername/ticketview.jsp?name=AAA




Options

Select 2 correct options.

1) Name : AAA

2)Price : 0

3)An exception stack trace.

4)Only this will be present:- Name : AAA

5)Translation error.
 
Sergey Tyulkin
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
your price attribute is of type int. When the bean is created, price gets default value - 0. Then, when setProperty is called, the container calls only setName (note: containers will call setters only for those properties, which are passed the query string). So, correct answer is 1 and 2
 
Pawan Ramchandani
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic