Object-oriented features of the Java learning package -----

Object-oriented characteristics of a, package (Encapsulation)
Package: refers to the hidden object properties and implementation details, only the external provision of public access.
Benefits:
 The change in isolation
 ease of use
 to improve reusability
 improve security
package principle:
 the content does not need to provide both are hidden
 the properties are hidden to provide public access methods allowed 
for example:

class Person
{
	private String name;
	private String sex;
	private int age;
	
	public getName()
	{
		return name;
	}
	public setName(String name)
	{
		this.name=name;
	}
	
	public getSex()
	{
		return sex;
	}
	public setSex(String sex)
	{
		this.sex=sex;
	}
	
	public getAge()
	{
		return age;
	}
	public setAge(int age)
	{
		if(age>1 && age<200)
			this.age=age;
	}
}

  

Guess you like

Origin www.cnblogs.com/WarBlog/p/12049155.html