为什么要这么写
public class CDBean
{
private String cdName;
private String cdCompany;
private String cdAlbum;
private String cdType;
private long cdId;
public CDBean()
{
}
public void setCdName(String cdName)
{
this.cdName = cdName;
}
public String getCdName()
{
return cdName;
}
public void setCdCompany(String cdCompany)
{
this.cdCompany = cdCompany;
}
public String getCdCompany()
{
return cdCompany;
}
public void setCdAlbum(String cdAlbum)
{
this.cdAlbum = cdAlbum;
}
public String getCdAlbum()
{
return cdAlbum;
}
public void setCdType(String cdType)
{
this.cdType = cdType;
}
public String getCdType()
{
return cdType;
}
public void setCdId(long cdId)
{
this.cdId = cdId;
}
public long getCdId()
{
return cdId;
}
}
学java已经有段时间了,感觉java是层次感很强的,我主要学web方向的,象这样写是不是为了让各个层次不乱?
------解决方案--------------------同LS的。
应该是问为什么要有访问器吧?
变量的private不允许外部直接调用,这样写比较安全和规范