• 【保存】


    点击查看代码
    package chap05;
    
    public class Contract {
    	private String name;
    	private String gender;
    	private String email;
    	private String[] phones;
    
    	public String getGender() {
    		return gender;
    	}
    
    	public void setGender(String gender) {
    		this.gender = gender;
    	}
    
    	public String getEmail() {
    		return email;
    	}
    
    	public void setEmail(String email) {
    		this.email = email;
    	}
    
    	public String[] getPhones() {
    		return phones;
    	}
    
    	public void setPhones(String[] phones) {
    		this.phones = phones;
    	}
    
    	public String getName() {
    		return name;
    	}
    
    	public Contract() {
    	}
    
    	public Contract(String name, String gender, String email, String[] phones) {
    		setName(name);
    		setGender(gender);
    		setEmail(email);
    		setPhones(phones);
    	}
    
    	public Contract(String name, String[] phones) {
    		this(name, "", "", phones);
    	}
    
    	//姓名不能为空
    	public void setName(String name) {
    		if (name == null || name.equals(""))
    			return;
    		this.name = name;
    	}
    
    	public void display() {
    		System.out.println("姓名:" + getName() + "	性别:" + getGender() + "	e-mail:" + getEmail());
    		System.out.print("联系电话:	");
    		for (int i = 0; i < phones.length; i++) {
    			System.out.print(phones[i] + "	");
    		}
    		System.out.println();
    	}
    
    	public static void main(String[] args) {
    		Contract c = new Contract("王新明", new String[] { "13602344578", "13506334789", "010-34567913" });
    		c.display();
    	}
    }
    
    
    点击查看代码
    package chap05;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class Family extends Contract {
    	
    	private Date birthday;
    	private String address;
    	
    	
    	public Family(String name, String gender, String email, String[] phones, Date birthday, String address) {
    		super(name, gender, email, phones);//调用父类的构造方法 必须是第一句话
    		setBirthday(birthday);
    		setAddress(address); 
    	}
    	public Family() {
    		
    	}
    	public Family(String name, String[] phones) {
    		super(name,phones);
    			
    		}
    	public Date getBirthday() {
    		return birthday;
    	}
    	public void setBirthday(Date birthday) {
    		this.birthday = birthday;
    	}
    	public String getAddress() {
    		return address;
    	}
    	public void setAddress(String address) {
    		this.address = address;
    	}
    	public void dispaly() {
    		super.display();//调用父类被重写的方法
    		 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    		System.out.println("生日"+this.getBirthday()+"	地址"+this.getAddress());
    	}
    	
    	
    
    }
    
    
    点击查看代码
    package chap05;
    
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class ContractTest {
    
    	public static void main(String[] args) throws ParseException {
    		Contract c = new Contract("王新明", new String[] { "13602344578", "13506334789", "010-34567913" });
    		c.display();
    		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    		Date birthday = sdf.parse("2001-09-12");	
    		
    		Family f = new Family("王虎", "男","wh@163.com",new String[] { "13602341234", "13506332356", "010-34564568" },birthday,"山东烟台");
    		f.display();
    //		Partner p = new Partner("张一鸣", "男","zym@163.com",new String[] { "13600041234", "13501232356" }, 
    //				"工程师", new Company("千度烟台", "烟台莱山区", "0535-6023458", "0535-6026457"));
    //		p.display();
    	}
    
    }
    
    
  • 相关阅读:
    Java中类与类的关系
    谈谈spring
    mybatis和hibernate的区别
    微信小程序文档解读(一)--api提供支持有哪些
    nodejs问题整理--fs.exists无法正确判断文件的问题
    微信小程序-多级联动
    react
    [微信小程序] 终于可以愉快的使用 async/await 啦
    [Node] 逃离回调地狱
    单例模式
  • 原文地址:https://www.cnblogs.com/zhujiaozhu/p/15355346.html
Copyright © 2020-2023  润新知