File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Mock Exam Q - confusing? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Mock Exam Q - confusing?" Watch "Mock Exam Q - confusing?" New topic
Author

Mock Exam Q - confusing?

Sehrish Hasan
Ranch Hand

Joined: Aug 15, 2005
Posts: 43
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

Joined: Dec 06, 2006
Posts: 41
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

Joined: Oct 16, 2005
Posts: 1277
all crap questions...
just remember the bean law....


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
 
jQuery in Action, 2nd edition
 
subject: Mock Exam Q - confusing?