• JAVA作业一


    public class java1 {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Dog dog =new Dog("大黄","黄",10); 
                dog.tell();
               
        }
    
    }
    
    
    class Dog{
        private String name;
        private String colour;
        private int age;
        public Dog(String name,String colour,int age){
              this.setName(name);
              this.setColour(colour);
              this.setAge(age);
             }
        
        public void tell(){
              System.out.println("名字:"+getName()+",颜色:"+getColour()+",年龄:"+getAge());
        }
         public String getName(){
              return name;
             }
             public void setName(String n){
              name = n;
             }
             
             public String getColour(){
              return colour;
             }
             public void setColour(String c){
              colour = c;
             }
             
             public int getAge(){
              return age;
             }
             public void setAge(int a){
                 age = a;
             }
            
    }
    public class Java2 {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
    
              User user1=new User("李四","131415");
              user1.print();
              User user2=new User("张三","215451");
              user2.print();
              new User().count();
             }
            }
    
            class User
            {
             private String name;
             private String password;
             private static int count;//count用于统计个数必须用static 声明成全局属性
             public User(){
              count++;
             }
             public User(String name){
              this.name=name;
              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 void print(){
              System.out.println("用户名:"+name+"	"+"口令:"+password);
             }
             public void count(){
              System.out.println("用户个数:"+(count-1));
             }
        }
  • 相关阅读:
    NOIP模拟 1
    wlan
    IS-IS IGP
    linux 基础 软件的安装 *****
    第五部分 linux 软件安装RPM SRPM与YUM
    第四部分 linux使用者管理
    添加rpmforge源 centos 7
    x86 保护模式 十 分页管理机制
    X86保护模式 八操作系统类指令
    poj2230 Watchcow【欧拉回路】【输出路径】(遍历所有边的两个方向)
  • 原文地址:https://www.cnblogs.com/zscswd1368/p/6600546.html
Copyright © 2020-2023  润新知