封装demo
package cn.xuexi; /* * 写了一个简单的封装类 * 结论:以后在开发中,类中全部属性都必须要封装,封装之后属性必须通过setter gettet进行访问 */ import java.nio.channels.Pipe; public class FengZhuangDemo { public static void main(String[] args) { person p1 = new person(); p1.setname("huhfdus"); p1.setage(65); System.out.println(p1.getname()+p1.getage()); } } class person{ private String name; private int age; public void setname(String name){ this.name = name; } public void setage(int age){ this.age = age; } public String getname() { return name; } public int getage(){ return age; } }