文章目录
一:什么是封装性1.封装性例题
一:什么是封装性
1.封装性例题
Person.java
package com
.xx
.study
;
public class Person {
private int age
;
public void setAge(int a
){
if(a
<0||a
>130) {
System
.out
.println("传入数据不合格");
return;
}
age
=a
;
}
public int getAge() {
return age
;
}
}
PersonTest.java
package com
.xx
.study
;
public class PersonTest {
public static void main(String
[] args
) {
Person p
=new Person();
p
.setAge(18);
System
.out
.println(p
.getAge());
}
}
转载请注明原文地址: https://lol.8miu.com/read-19092.html