• Java第四次作业


    		Dog dog=new Dog("哈士奇","黑白",2);
    		  System.out.println(dog);
    		 }
    		}
    	class Dog {
    		private String name;
    		private String color;
    		private int age;
    		public String getName(){
    		return name;
    	}
    	public String getColor(){
    		return color;
    	}
    	public int getAge(){
    		return age;
    	}
    	public void setName(String name){
    		this.name=name;
    	}
    	public void setColor(String color){
    		this.color=color;
    	}
    	public void setAge(int age){
    		this.age=age;
    	}
    	public Dog(String name,String color,int age){
    		super();
    		this.name=name;
    		this.color=color;
    		this.age=age;
    	}
    	public String toString(){
    		return "狗的名字:"+this.name+",狗的颜色:"+this.color+",狗的年龄:"+this.age;
    	 }
    }
    
    package core;
    public class Y2 {
    	public static void main(String[] args) {
    		// TODO 自动生成的方法存根
    		User user1=new User("黑王","545789");
    		user1.print();
    		User user2=new User("红六","754582");
    		user2.print();
    		new User().count();
    	}
    }
    class User
    {
    	private String name;
    	private String password;
    	private static int count;
    	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));
     }
    }
    

      

  • 相关阅读:
    解决SSH连接Linux超时自动断开
    小程序选项卡
    vue 封装axios 请求 统一管理方法1
    vue 中使用echar
    vue element 做表格分页
    vue echar使用
    旋转
    vue 登录切换页面
    vue 根据输入的身份号码,自动获取年龄
    vue 手机号码验证 。点击获取验证码
  • 原文地址:https://www.cnblogs.com/ouyu/p/6607212.html
Copyright © 2020-2023  润新知