码迷,mamicode.com
首页 > 其他好文 > 详细

第四次作业

时间:2016-04-08 14:48:21      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

class Dog
{
private String name;
private String colour;
private int age;
public Dog(String name,String colour,int age)
{
this.name=name;
this.colour=colour;
this.age=age;
}
public void print()
{
System.out.println("名字:"+this.name+"\n"+"颜色:"+this.colour+"\n"+"年龄:"+this.age);
}
}
class Demo01
{
public static void main(String args[])
{
Dog dog=new Dog("米奇","黑色",3);
dog.print();
}
}

 技术分享

class User
{
private String name;
private String password;
private static int count=0;
public User()
{
count++;
}
public User(String name)
{
count++;
this.name=name;
}
public User(String name,String password)
{
count++;
this.name=name;
this.password=password;
}
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 void print()
{
System.out.println("用户个数:"+count);
System.out.println("用户名:"+this.name+"\t"+"密码:"+this.password);
}
}
public class Demo02
{
public static void main(String args[])
{
User user1=new User("Ann","12845");
user1.print();
User user2=new User("Ken","12445");
user2.print();
User user3=new User("Jane","12345");
user3.print();
}
}

技术分享

 

第四次作业

标签:

原文地址:http://www.cnblogs.com/yanyuying/p/5367703.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!