标签:pass ati system out str 颜色 word 题目 home
题目一:
public class HomeworkDog {
public static void main(String[] args) {
Dog per=new Dog("Luckly","金黄色","三个月","金毛");
per.tell();
}
}
class Dog{
private String Name;
private String Colour;
private String Age;
private String Nature;
public Dog(String Name,String Colour,String Age,String Nature){
this.setName(Name);
this.setColour(Colour);
this.setAge(Age);
this.setNature(Nature);
}
public void tell(){
System.out.println("名字:"+getNature()+",颜色:"+getColour()+",年龄:"+getAge()+",属性:"+getNature());
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getColour() {
return Colour;
}
public void setColour(String colour) {
Colour = colour;
}
public String getAge() {
return Age;
}
public void setAge(String age) {
Age = age;
}
public String getNature() {
return Nature;
}
public void setNature(String nature) {
Nature = nature;
}
}
题目二:
public class Work {
public static void main(String[] args) {
User per1=new User("张三","1");
per1.print();
User per2=new User("李四","2");
per2.print();
new User().count();
}
}
class User{
private String Name;
private String Password;
private static int count;
public User(){
count++;
}
public User(String Name,String Password){
this.Name=Name;
this.Password=Password;
count++;
}
public String getName() {
return Name;
}
public void setName(String name) {
this.Name = name;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
this.Password = password;
}
public static int getCount() {
return count;
}
public static void setCount(int count) {
User.count = count;
}
public void print(){
System.out.println("用户名:"+Name+"\t"+"口令密码:"+Password);
}
public void count(){
System.out.println("用户个数:"+(count-1));
}
}
标签:pass ati system out str 颜色 word 题目 home
原文地址:http://www.cnblogs.com/naima/p/6606776.html