Java类的组成
我想说的是,Java运用就是一个类又一个类。Java是面向目标的言语,目标都是由类实例化而来。一个Java运用,不管简略仍是杂乱,都是由若干个Java类组成的。因而,关于初学者,先知道Java类的组成是必要的。
Java类的组成首要有3有些:数据成员、结构办法、办法成员。
首要看下边的代码,是一个简略的Java类:
packagecom.csst.vo;
publicclassCustomer{
//1.数据成员
privateStringcustname;
privateStringpwd;
privateIntegerage;
//2.结构办法
publicCustomer(){
}
publicCustomer(Stringcustname,Stringpwd){
this.custname=custname;
this.pwd=pwd;
}
publicCustomer(Stringcustname,Stringpwd,Integerage){
super();
this.custname=custname;
this.pwd=pwd;
this.age=age;
}
//3.办法成员
publicStringgetCustname(){
returncustname;
}
publicvoidsetCustname(Stringcustname){
this.custname=custname;
}
publicStringgetPwd(){
returnpwd;
}
publicvoidsetPwd(Stringpwd){
this.pwd=pwd;
}
publicIntegergetAge(){
returnage;
}
publicvoidsetAge(Integerage){
this.age=age;
}