封装
public class Pet {
private String name;
private int age;
//无参构造
public void shout(){
System.out.println("叫了一声");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
/*
1.提高程序的安全性,保护数据
2.隐藏代码的实现细节
3.统一接口
4.系统可维护增加了
*/
public class Application {
public static void main(String[] args) {
Pet pet=new Pet();
pet.setName("旺财");
String name=pet.getName();
System.out.println(name);
}
}
继承