Content deleted Content added
m +pt:IW |
Added boolean field example |
||
Line 17:
== JavaBean Example ==
<pre>
private String name;▼
private
public PersonBean() {▼
private boolean alive;
// Our constructor. Note that it takes no arguments.▼
}<BR>▼
public void setName(String n) {▼
this.name = n;▼
}<BR>▼
public void setAge(int a) {▼
this.age = a;▼
public String getName() { return (this.name); }▼
public int getAge() { return (this.age); }▼
}▼
person.setName("Bob");▼
System.out.println(person.getName());▼
▲ public void setName(String n) {
▲ this.name = n;
▲ this.age = a;
}
this.deceased = deceased;
}
▲ public String getName() { return (this.name); }
▲ public int getAge() { return (this.age); }
// note slightly different semantics for a boolean field (*is* vs. *get*)
public boolean isDeceased() { return (this.deceased); }
PersonBean person = new PersonBean();
person.setAlive(false);
</pre>
== See also ==
|