[size=x-small]设计一个表示用户的类User,类中有用户名,口令(私有的)和记录用户数(静态)的成员变量,定义类的构造方法,设置和获取口令的方法及返回类的对象信息的方法(包括用户名和口令)[/size]
public class User {
public String userName;
private String password;
public static int num = 0;
public User(String userName, String password) {
// 构造方法,初始化
this.userName = userName;
this.password = password;
num++;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getInfo() {
return userName + "&" + password;
}
}
s[code="java"]
<?php
echo 'dd';
[/code]
public class User {
// 设计一个表示用户的类User,类中有用户名,
// 口令(私有的)和记录用户数(静态)的成员变量,
// 定义类的构造方法,设置和获取口令的方法及返回类的对象信息的方法(包括用户名和口令)
private String userName=null;
private String password=null;
private static long count=0L;
public User(){
this.userName="张三";
this.password="123";
this.count=23;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public long getCount() {
return count;
}
public void setCount(long count) {
this.count = count;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
@Override
public String toString() {
return "User [userName=" + userName + ", password=" + password
+ ", count=" + count + "]";
}
public static void main(String args[]){
User user=new User();
System.out.println(user.toString());
}
}