Java Reference
In-Depth Information
used in place of a get method. For example, the following two method signa-
tures create a Boolean property named atHome:
public void setAtHome(boolean b)
public boolean isAtHome()
The name of a property is determined by the method signatures for the
property. The set or get portion of the method name is removed, and the
next letter is decapitalized. For example, the following two methods
create a property named length of type int:
public void setLength(int x)
public int getLength()
The exception to the decapitalization rule occurs when the property name
is all capitals, such as the following:
public String getURL()
public void setURL(String s)
These two methods create a read-write property of type String whose
name is URL.
Study the following Movie class and see if you can determine its bean prop-
erties, including their name, their data type, and whether they are read-only,
write-only, or read-write:
package video.store;
public class Movie implements java.io.Serializable
{
private String title;
private int length;
private boolean rented;
private String customer;
public Movie()
{
System.out.println(“Constructing a movie...”);
customer = “”;
}
public void setTitle(String t)
{
System.out.println(“Setting the title to “ + t);
title = t;
}
public String getTitle()
{
Search WWH ::




Custom Search