2020-11-24

在这里插入图片描述

package Thirdweek;

import java.util.Scanner;

public class TestObject {
	public static void main(String[] args) {
		User u1=getUser();
		User u2=getUser();
	}
	public static User getUser() {
		System.out.println("请输入用户名:");
		Scanner sc=new Scanner(System.in);
		String username=sc.next();
		System.out.println("请输入密码:");
		String password=sc.next();
		System.out.println("请输入电话号码:");
		String tel=sc.next();
		User u1=new User(username,password,tel);
		return u1;
	}
}
class User{
	private String username;
	private String password;
	private String tel;
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	
	public User(String username) {
		super();
		this.username = username;
	}
	public User(String username, String password, String tel) {
		this.username = username;
		this.password=password;
		this.tel=tel;
	}
	@Override
	public String toString() {
		username="一如既往";
		password="123456";
		tel="13051800688";
		return "User [username=" + username + ", password=" + password + ", tel=" + tel + "]";
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((username == null) ? 0 : username.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		return true;
	}
	
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值