zoukankan      html  css  js  c++  java
  • 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));
             }
        }
  • 相关阅读:
    Codeforces 每日一练 1213G+961E+1282B2
    AtCoder Beginner Contest 161题解
    Codeforces每日一练 495B+55C+1280C
    CF1062E 线段树/LCA
    Codeforces Round #697 (Div. 3) 题解
    Codeforces Round #511 (Div. 2) A~D题解
    Atcoder ABC 189 题解
    CF1093G 高维曼哈顿距离/线段树
    CF1117D Magic Gems 矩阵快速幂 DP
    CF1106E Lunar New Year and Red Envelopes DP
  • 原文地址:https://www.cnblogs.com/zscswd1368/p/6600546.html
Copyright © 2011-2022 走看看