JAVA面向对象程序设计-FeiGe快递系统-封装

70 阅读1分钟

JAVA面向对象程序设计


在这里插入图片描述


public class lesson_1 {
	  static int j;
	  static int s=80;
	  int i;
	  int k= 55;
	  static {
		  j=5;
		  System.out.println("j的初始值为:"+j);
		  
	  }
	public  lesson_1(){
		i=20;
		System.out.println("i的初始值为:"+i);
	}
	public static void getNum(){
		System.out.println("得到j的值为:"+j);
	}
	public static void main(String[] args){
		lesson_1 st=new lesson_1();
		System.out.println("j的值为:"+lesson_1.j);
		st.getNum();
		System.out.println("s的值为:"+st.s);
		System.out.println("k的值为:"+st.k);
	}
	
}

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

public class person {
	private String P_id;
	private String name;
	private char sex;
	private int age;
	private String address;
	private String password;
	private int type;
	private String telnum;
	public String setName;
	public String getP_id() {
		return P_id;
	}
	public void setP_id(String pId) {
		P_id = pId;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public char getSex() {
		return sex;
	}
	public void setSex(char sex) {
		this.sex = sex;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		if (age>=1&& age<=130) {
			this.age = age;
		} else {
System.out.println("输入的年龄不合法!");
		}
		
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public String getTelnum() {
		return telnum;
	}
	public void setTelnum(String telnum) {
		this.telnum = telnum;
	}

}

在这里插入图片描述


public class Testperson {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		person person =new person();
		person.setName("李四");
		person.setSex('女');
		person.setAge(20);
		person.setName("张三");
		person.setSex('男');
		person.setAge(5);
		System.out.println("姓名:"+person.getName()+"\n性别:"+person.getSex()+
				"\n年龄:"+person.getAge());

	}

}