• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about jsp:useBean from mock test by anand chawala

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question for Java Beans.
The contents of beans class are as follows:-
package projsp;
public class trying
{
private String name;
private int age;
public void setName(String n)
{
name=n;
}
public void setAge(int a)
{
age=a;
}

public int getAge()
{
return age;
}
public String getName()
{
return name;
}
}
The contents of test.jsp file are as follows:
<%@ page language="java" import="projsp.*" %>
<jsp:useBean id="test" class="projsp.trying" />
<html>
The Name is <getProperty name="test" property="name" />
The Age is < jsp:getProperty name="test" property="age" />
</html>
If a user types in http://servername:8080/test.jsp?name=Anand&age=22 the out put is
Options given are:
1.Name is Anand
Age is 22
2.Name is Null
Age is 0
3.Name is Null
Age is Null
4.It gives a compilation error as the roperties are not set prior to retrieving them

The correct answer given is 3.
But When I tries the above example on my PC using tomcat4 I got the result as
The Name is
The Age is 0
so What exactly is the correct answer? is it 2? if I consider blank is null?
thanks,
Trupti
[ November 09, 2002: Message edited by: trupti nigam ]
 
Adrian Muscalu
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't tried the example but it seems to me you're right. A primitive instance variable is instantiated with the default value for it's type.
Anand was wrong.
Adrian
 
Hafizur Rahman
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,
I was shocked with this question. Primitive int members take a default value 0 and objects null. Unfortunately the question maker is mistaken. I think its only a slip of question making.
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic