java封装基础练习


```java
package cn.tedu.object;


//把一个Student类封装起来,模拟一个转校生转入新学校后为其制作学生信息的过程。
public class 封装_制作入学信息 {

	public static void main(String[] args) {
		Student s1 = new Student();
		s1.setSchool_number(26);
		s1.setName("李灰尘");
		s1.setGender("男");
		s1.setPlace("北京市海淀区");
		s1.setFu_number("130****1100");
		s1.setMu_number("133****5678");
		
		print p1 = new print();
		print p2 = new print(s1.getSchool_number(), s1.getName(), s1.getGender(), s1.getPlace(), s1.getFu_number(),s1.getMu_number());

	}

}
class print{
	public print() {
		System.out.println("转校生李灰尘的学生信息如下:");
		System.out.println("--------------------------------------------------");
		System.out.println("学号\t姓名\t性别\t籍贯\t\t父母的联系方式");
		System.out.println("--------------------------------------------------");
	}
	public  print(int s, String n, String g, String p, String f, String m) {
		System.out.println(s + "\t" + n + "\t" + g +"\t"+ p + "\t父:" + f +"\n\t\t\t\t\t母:" + m);
}
}
class Student{
	private int school_number;//school_number 学号
	private String name;
	private String gender;//gender 性别
	private	String place;//place 地址
	private String fu_number;
	private String mu_number;
	
	public void setSchool_number(int s) {
		school_number = s;
	}
	public int getSchool_number() {
		return school_number;
	}
	public void setName(String n) {
		name = n;
	}
	public String getName() {
		return name;
	}
	public void setGender(String g) {
		gender = g;
	}
	public String getGender() {
		return gender;
	}
	public void setPlace(String p) {
		place = p;
	}
	public String getPlace() {
		return place;
	}
	public void setFu_number(String f) {
		fu_number = f;
	}
	public String getFu_number() {
		return fu_number;
	}
	public void setMu_number(String m) {
		mu_number = m;
	}
	public String getMu_number() {
		return mu_number;
	}
}

/*转校生李灰尘的学生信息如下:
--------------------------------------------------
学号	姓名	性别	籍贯		父母的联系方式
--------------------------------------------------
26	李灰尘	男	北京市海淀区	父:130****1100
					母:133****5678
*/



你可能感兴趣的:(笔记,java)