Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock Exam Q - confusing?

 
Sehrish Hasan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Here is the question I found in one of the mock exams:

Examine the following code and select the correct options:

public class ProductBean implements java.io.Serializable {
private String productName;
private int quantity;

public void setName (String newVal) { productName = newVal; }
public String getName () { return productName; }

public void setWeight (int newVal) { quantity = newVal; }
public int getWeight () { return quantity; }
}


A) ProductBean defines two properties.
B) ProductBean defines one readable property 'name'.
C) ProductBean defines one writable property 'name'.
D) ProductBean defines one readable property 'productName'.
E) ProductBean defines one writable property 'productName'.
F) ProductBean defines one readable and writeable property 'weight'.
G) ProductBean defines one readable and writeable property 'quantity'.
H) ProductBean is not a valid JavaBean because it does not defines a public no-argument constructor.

The answer given is: A, B, C, F

and here is the explanation for the answers:
D) Option D is incorrect because the name of a bean property is derived from the name of its methods, not from the name of the variables used to store the value of a property.
E) Option E is incorrect because the name of a bean property is derived from the name of its methods, not from the name of the variables used to store the value of a property.
G) Option G is incorrect because the name of a bean property is derived from the name of its methods, not from the name of the variables used to store the value of a property.
H) Option H is incorrect. If a bean does not defines any constructor, Java compiler defines a no-argument constructor for it, which is one of the requirements to qualify as a valid JavaBean.

Could somebody explain this to me? I think the answer should be along the lines that ProductBean is not a bean because it doesnt have setters and getters for the properties and thats one of the requirements of a bean.

Thanks,
Mahrukh.
 
Vipul Tulsulkar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How can you say that class productBean doesn't contain getters & setters
when they are so clearly given in the code extract?

public void setName (String newVal) { productName = newVal; }
public String getName () { return productName; }

public void setWeight (int newVal) { quantity = newVal; }
public int getWeight () { return quantity; }

The properties are name & weight,which have been clearly set & get.
Isuggest you to refer HFSJ to get a very good understanding of javabean, getter & setter.

Regards,
Vipul
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all crap questions...
just remember the bean law....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic