1.封装性定义:不是直接通过“对象.属性”对属性进行操作访问,而是通过“对象.方法”来控制对属性的操作访问;
2.实现封装性则为将类的属性私有化,通过“setter&getter”来实现对对象的操作访问;
3.e。g。
public class Setgetting {
public static void main(String[] args) {
Setgetter sg=new Setgetter();
sg.setScore(234423423);
sg.setAssist(1212123);
sg.setRebound(2323233);
System.out.println("老科退役砍下吓哭耶稣的三双数据,"+sg.getScore()+"分 ,"+sg.getAssist()+"助攻 ,"+sg.getRebound()+"个篮板lol");
}
}
class Setgetter{
private int score;
private int rebound;
private int assist;
public int getScore(){
return score;
}
public void setScore(int score){
this.score=score;
}
public int getAssist(){
return assist;
}
public void setAssist(int assist){
this.assist=assist;
}
public int getRebound(){
return rebound;
}
public void setRebound(int rebound){
this.rebound=rebound;
}
}
编译运行
老科退役砍下吓哭耶稣的三双数据,234423423分 ,1212123助攻 ,2323233个篮板lol